c ++ visual studio 2008链接问题

时间:2009-11-06 07:06:26

标签: c++ visual-studio-2008 build linker

当我构建我的项目时,它编译得很好,但是当链接它时会抛出大量的LNK错误!错误LNK2001,错误LNK2005,错误列表中存在错误LNK2019

>Linking...
1>MultiCatAttributeInfo.obj : error LNK2019: unresolved external symbol "public: class std::vector<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::allocator<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > > > __thiscall MultiCatItem::value(void)const " (?value@MultiCatItem@@QBE?AV?$vector@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V?$allocator@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@2@@std@@XZ) referenced in function "public: virtual class boost::dynamic_bitset<unsigned long,class std::allocator<unsigned long> > __thiscall MultiCatAttributeInfo::encode(class Item *)" (?encode@MultiCatAttributeInfo@@UAE?AV?$dynamic_bitset@KV?$allocator@K@std@@@boost@@PAVItem@@@Z)

我该如何克服这个问题?我使用visual studio 2008,我的解决方案有几个项目;所有给出如上所述的链接错误!!!

4 个答案:

答案 0 :(得分:1)

如果您正在使用DLL,则可能是您未通过设置__declspec(dllexport)(以及在其他项目中导入头文件时__declspec(dllimport))正确导出您的类。然后链接器无法看到函数/类。

答案 1 :(得分:0)

好吧,看起来你没有链接一些文件。你检查过以确保你实际编译了所有的源文件吗?

没有任何代码,很难说出具体的内容。

答案 2 :(得分:0)

错误表示您尚未实现或链接函数MultiCatItem::value中引用的函数MultiCatAttributeInfo::encode。检查您是否在项目中包含了具有MultiCatItem实现的相应cpp文件。

答案 3 :(得分:0)

链接器正在尝试查找MultiCatItem::value函数的实现,它将在obj文件(即编译的cpp文件)或编译库(即.lib文件中指定)中找到。链接器属性输入节)。

链接器可以理解为非常迂腐,所以如果你链接到已编译的lib,请确保编译的库是使用相同的设置编译的,例如,编译的lib不是使用Unicode设置编译的,这意味着该方法的签名将从使用char更改为wchar_t

如果您使用已编译的库,请使用工具dumpbin从.lib转储所有导出的函数/类等,例如

dumpbin.exe /all somelibrary.lib > out.txt

并检查问题链接引用的签名在.lib中与Visual Studio正在查找的相同。