【IDE-Visual Studio】StdAfx.obj : error LNK2001: 无法解析的外部符号

问题

1>StdAfx.obj : error LNK2001: 无法解析的外部符号 "public: virtual bool __thiscall CxMemFile::Close(void)" (?Close@CxMemFile@@UAE_NXZ)
1>StdAfx.obj : error LNK2001: 无法解析的外部符号 "public: virtual unsigned int __thiscall CxMemFile::Read(void *,unsigned int,unsigned int)" (?Read@CxMemFile@@UAEIPAXII@Z)
1>StdAfx.obj : error LNK2001: 无法解析的外部符号 "public: virtual unsigned int __thiscall CxMemFile::Write(void const *,unsigned int,unsigned int)" (?Write@CxMemFile@@UAEIPBXII@Z)
1>StdAfx.obj : error LNK2001: 无法解析的外部符号 "public: virtual bool __thiscall CxMemFile::Seek(long,int)" (?Seek@CxMemFile@@UAE_NJH@Z)
1>StdAfx.obj : error LNK2001: 无法解析的外部符号 "public: virtual long __thiscall CxMemFile::Tell(void)" (?Tell@CxMemFile@@UAEJXZ)
1>StdAfx.obj : error LNK2001: 无法解析的外部符号 "public: virtual long __thiscall CxMemFile::Size(void)" (?Size@CxMemFile@@UAEJXZ)
1>StdAfx.obj : error LNK2001: 无法解析的外部符号 "public: virtual bool __thiscall CxMemFile::Flush(void)" (?Flush@CxMemFile@@UAE_NXZ)
1>StdAfx.obj : error LNK2001: 无法解析的外部符号 "public: virtual bool __thiscall CxMemFile::Eof(void)" (?Eof@CxMemFile@@UAE_NXZ)
1>StdAfx.obj : error LNK2001: 无法解析的外部符号 "public: virtual long __thiscall CxMemFile::Error(void)" (?Error@CxMemFile@@UAEJXZ)
1>StdAfx.obj : error LNK2001: 无法解析的外部符号 "public: virtual bool __thiscall CxMemFile::PutC(unsigned char)" (?PutC@CxMemFile@@UAE_NE@Z)
1>StdAfx.obj : error LNK2001: 无法解析的外部符号 "public: virtual long __thiscall CxMemFile::GetC(void)" (?GetC@CxMemFile@@UAEJXZ)
1>StdAfx.obj : error LNK2001: 无法解析的外部符号 "public: virtual char * __thiscall CxMemFile::GetS(char *,int)" (?GetS@CxMemFile@@UAEPADPADH@Z)
1>StdAfx.obj : error LNK2001: 无法解析的外部符号 "public: virtual long __thiscall CxMemFile::Scanf(char const *,void *)" (?Scanf@CxMemFile@@UAEJPBDPAX@Z)
1>StdAfx.obj : error LNK2019: 无法解析的外部符号 "public: __thiscall CxMemFile::CxMemFile(unsigned char *,unsigned long)" (??0CxMemFile@@QAE@PAEK@Z),该符号在函数 "public: void __thiscall CxMemFile::`default constructor closure'(void)" (??_FCxMemFile@@QAEXXZ) 中被引用
1>StdAfx.obj : error LNK2019: 无法解析的外部符号 "public: virtual __thiscall CxMemFile::~CxMemFile(void)" (??1CxMemFile@@UAE@XZ),该符号在函数 "public: virtual void * __thiscall CxMemFile::`scalar deleting destructor'(unsigned int)" (??_GCxMemFile@@UAEPAXI@Z) 中被引用
1>E:\赛智工作项目\TS8bit\sln2\Debug\GelPrj.exe : fatal error LNK1120: 15 个无法解析的外部命令
1>生成日志保存在“file://e:\赛智工作项目\TS8bit\source\Debug\BuildLog.htm”
1>GelPrj - 16 个错误,5 个警告
========== 生成: 0 已成功, 1 已失败, 0 最新, 0 已跳过 ==========

原因

在包含头文件中的函数没有引用时,头文件的class 后有__declspec(dllexport)的导出符号标识,而没有添加实现文件,导致出现无法解析的情况,如下列代码

class DLL_EXP CxMemFile : public CxFile中的DLL_EXP 的定义就是__declspec(dllexport)导出标识符。

#if !defined(__xmemfile_h)
#define __xmemfile_h

#include "xfile.h"

//
#if defined(_AFXDLL)||defined(_USRDLL)
#define DLL_EXP __declspec(dllexport)
#elif defined(_MSC_VER)&&(_MSC_VER<1200)
#define DLL_EXP __declspec(dllimport)
#else
#define DLL_EXP
#endif

class DLL_EXP CxMemFile : public CxFile
{
public:
	CxMemFile(BYTE* pBuffer = NULL, DWORD size = 0);
	~CxMemFile();

	bool Open();
	BYTE* GetBuffer(bool bDetachBuffer = true);

	virtual bool	Close();
	virtual size_t	Read(void *buffer, size_t size, size_t count);
	virtual size_t	Write(const void *buffer, size_t size, size_t count);
	virtual bool	Seek(long offset, int origin);
	virtual long	Tell();
	virtual long	Size();
	virtual bool	Flush();
	virtual bool	Eof();
	virtual long	Error();
	virtual bool	PutC(unsigned char c);
	virtual long	GetC();
	virtual char *	GetS(char *string, int n);
	virtual long	Scanf(const char *format, void* output);

protected:
	bool	Alloc(DWORD nBytes);
	void	Free();

	BYTE*	m_pBuffer;
	DWORD	m_Size;
	bool	m_bFreeOnClose;
	long	m_Position;	//current position
	long	m_Edge;		//buffer size
};

#endif


解决方案 

方法一、去掉导出符号__declspec(dllexport)

方法二、添加实现文件

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值