奇怪的LNK2001链接器错误

时间:2012-02-03 09:31:03

标签: c++ linker

昨天我收到了这个链接器错误。我搜索了谷歌和msdn没有成功。 我的问题: 我已将我的cpp项目的某些部分移动到extern静态库中。我将h文件添加到我的主项目中,并将依赖项添加到lib文件中。不幸的是,我收到了很多链接器错误。

1>Compressor.obj : error LNK2001: unresolved external symbol "public: bool __thiscall NWindows::NFile::NFind::CFileInfo::Find(unsigned short const *)" (?Find@CFileInfo@NFind@NFile@NWindows@@QAE_NPBG@Z)
1>Compressor.obj : error LNK2001: unresolved external symbol "public: class NWindows::NCOM::CPropVariant & __thiscall NWindows::NCOM::CPropVariant::operator=(unsigned short const *)" (??4CPropVariant@NCOM@NWindows@@QAEAAV012@PBG@Z)
1>Compressor.obj : error LNK2001: unresolved external symbol "public: bool __thiscall CInFileStream::Open(unsigned short const *)" (?Open@CInFileStream@@QAE_NPBG@Z)
1>Compressor.obj : error LNK2001: unresolved external symbol "public: bool __thiscall NWindows::NFile::NIO::COutFile::Create(unsigned short const *,bool)" (?Create@COutFile@NIO@NFile@NWindows@@QAE_NPBG_N@Z)
1>Compressor.obj : error LNK2001: unresolved external symbol "void __cdecl ConvertUInt32ToString(unsigned int,unsigned short *)" (?ConvertUInt32ToString@@YAXIPAG@Z)
1>Compressor.obj : error LNK2001: unresolved external symbol "public: bool __thiscall NWindows::NDLL::CLibrary::Load(unsigned short const *)" (?Load@CLibrary@NDLL@NWindows@@QAE_NPBG@Z)

所有这些方法都是我的extern lib的一部分。我尝试了很多编译器设置而没有成功。 当我从链接器中完全删除lib dependencie时,我得到26 LNK2001错误。因此链接器只找到lib的“部分”。 我的项目是否使用了错误的编译器/链接器选项?

编辑: 问题是方法CLibrary :: Load(LPCTSTR fileName)的参数定义LPCTSTR。在我的lib中,我将选项“将wchar_t作为内置类型(属性 - > C / C ++ - > Lanuage-> ...)”设置为否。现在它可以正常工作。

1 个答案:

答案 0 :(得分:0)

问题中没有足够的信息,所以我的答案仅作为指导。

使用一个函数,例如bool NWindows::NFile::NFind::CFileInfo::Find(unsigned short const *),并在代码中找到它的定义。它在那里吗?有了这个确切的功能签名?它是否在未命名的命名空间中?它在源文件中声明为静态吗?

此外,尝试完全重建一切。你会惊讶地发现完全重建多次会让神秘问题消失。