奇怪的LNK2001链接器错误

Strange LNK2001 linker error

本文关键字:错误 链接 LNK2001      更新时间:2023-10-16

昨天我收到了这个链接器错误。我在谷歌和msdn上搜索过,但没有成功。我的问题:我已经在外部静态库中移动了cpp项目的一些部分。我将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)

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

编辑:问题是方法CLibrary::Load(LPCTSTR fileName)的参数定义LPCTSTR。在我的库中,我将选项"将wchar_t视为内置类型(Properties->C/C++->Lanuage->…)"设置为No。现在它可以工作了。

问题中没有足够的信息,所以我的回答只是一个指南。

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

此外,尝试全面重建一切。你会惊讶于有多少次完全重建会让神秘的问题消失。

相关文章: