简体   繁体   English

c ++ visual studio 2008链接问题

[英]c++ visual studio 2008 Linking problem

When I build my project it compiles well, but when Linking it throws huge number of LNK errors! 当我构建项目时,它可以很好地编译,但是在链接时,它将引发大量的LNK错误! error LNK2001, error LNK2005, error LNK2019 were there in the error list 错误列表中出现错误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)

how do I overcome this problem? 我该如何克服这个问题? Im using visual studio 2008, my solution has several projects; 我使用Visual Studio 2008,我的解决方案有多个项目; all give Linking errors like above!!! 都给像上面的链接错误!

If you're using DLLs, it could be that you haven't properly exported your classes by setting __declspec(dllexport) (and __declspec(dllimport) when importing the header file in other projects). 如果您使用的是DLL,则可能是您未通过设置__declspec(dllexport) (在其他项目中导入头文件时设置__declspec(dllimport)正确导出类。 Then the linker is unable to see the functions/classes. 这样,链接器将看不到功能/类。

Well, it looks like you're not linking some files in. Have you checked to make sure you're actually compiling all of your source files? 好吧,看来您没有链接某些文件。是否检查过您是否确实在编译所有源文件?

It's hard to say anything specific without any code. 没有任何代码,很难说出任何具体的东西。

Error says that you are have not implemented or linked function MultiCatItem::value that referenced in function MultiCatAttributeInfo::encode . 错误表明您尚未实现或链接在函数MultiCatAttributeInfo::encode中引用的函数MultiCatItem::value Check that you included appropriate cpp file with MultiCatItem implementation in the project. 检查您在项目中的MultiCatItem实现中是否包含了适当的cpp文件。

The linker is trying to find an implementation for the MultiCatItem::value function, which it will find in either an obj file (ie a compiled cpp file) or a compiled library (ie a .lib file, specified in the linker properties Input section). 链接器正在尝试找到MultiCatItem::value函数的实现,它将在链接器属性“输入”部分中指定的obj文件(即,编译的cpp文件)或已编译的库(即,.lib文件)中找到)。

The linker is understandably quite pedantic so if you're linking to a compiled lib make sure that the compiled library was compiled with the same settings and, for example, your compiled lib was not compiled with Unicode settings, which would mean that the signature for the method would change from using char to wchar_t . 可以理解,链接器是很老套的,因此,如果要链接到已编译的库,请确保已使用相同的设置来编译已编译的库,例如,未使用Unicode设置来编译已编译的库,这意味着该库的签名该方法将从使用char更改为wchar_t

If you are using compiled libs use the tool dumpbin to dump out all exported functions/classes etc. from the .lib, eg 如果您使用的是编译的库,请使用工具dumpbin从.lib中转储所有导出的函数/类等,例如

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

and check that the signatures of the problem link reference is the same in the .lib as Visual Studio is looking for. 并检查.lib中问题链接引用的签名是否与Visual Studio正在查找的签名相同。

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

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