繁体   English   中英

c ++ visual studio 2008链接问题

[英]c++ visual studio 2008 Linking problem

当我构建项目时,它可以很好地编译,但是在链接时,它将引发大量的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,我的解决方案有多个项目; 都给像上面的链接错误!

如果您使用的是DLL,则可能是您未通过设置__declspec(dllexport) (在其他项目中导入头文件时设置__declspec(dllimport)正确导出类。 这样,链接器将看不到功能/类。

好吧,看来您没有链接某些文件。是否检查过您是否确实在编译所有源文件?

没有任何代码,很难说出任何具体的东西。

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

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

可以理解,链接器是很老套的,因此,如果要链接到已编译的库,请确保已使用相同的设置来编译已编译的库,例如,未使用Unicode设置来编译已编译的库,这意味着该库的签名该方法将从使用char更改为wchar_t

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

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM