提高::线程的生成错误(无法链接的lib和放大器;&安培;无法解析的外部) [英] boost::thread build error (unable to link lib && unresolved external)
问题描述
我想在VS 2008跟随升压的一个简单的教程::线程(版本1.4-3):
I'm trying to follow a simple tutorial of Boost::Thread (ver 1.4-3) in VS 2008:
#include <boost/thread/thread.hpp>
void Func()
{
// Do something
}
void main()
{
boost::thread _thrd(&Func);
_thrd.join();
....
}
在编译过程中它会产生这个错误:
During compilation it produces this error:
Error 1 fatal error LNK1104: cannot open file 'libboost_thread-vc90-mt-gd-1_43.lib' CConsole
我有,加入的#define BOOST_ALL_NO_LIB
来解决。
然而,它给了我另一个错误:
which I have to resolve by adding #define BOOST_ALL_NO_LIB
.
However, it gives me another error:
Error 3 fatal error LNK1120: 2 unresolved externals
C:\xx\Documents\Visual Studio 2008\Projects\CConsole\Debug\CConsole.exe
Error 1 error LNK2019: unresolved external symbol "public: __thiscall boost::thread::~thread(void)" (??1thread@boost@@QAE@XZ) referenced in function _wmain CConsole.obj
Error 2 error LNK2019: unresolved external symbol "private: void __thiscall boost::thread::start_thread(void)" (?start_thread@thread@boost@@AAEXXZ) referenced in function "public: __thiscall boost::thread::thread<void (__cdecl*)(void)>(void (__cdecl*)(void),struct boost::thread::dummy *)" (??$?0P6AXXZ@thread@boost@@QAE@P6AXXZPAUdummy@01@@Z) CConsole.obj
有谁知道如何解决这个问题?
Does anyone know how to resolve the issue?
感谢。
推荐答案
我觉得更深层次的答案不是阅读他妈的手册可能会有所帮助!
I think a deeper answer than "Read the F*cking Manual" might be helpful!
这种链接错误是一个线索,你试图链接不兼容的Boost库。
This kind of link error is a clue that you're trying to link an incompatible Boost library.
我得到这个,当我错误地建立了一个32位的升压线程库时,我还以为是建立一个64位的库。过了一段时间,以弄清楚,当你说 - 地址模型= 64
作为的bjam命令行参数,你已经做出了细微的错误。在地址模型
参数绝不能有 -
preFIX。不幸的是,当它看到不正确的语法的bjam不会通知您。
I got this when I mistakenly built a 32 bit Boost thread library when I thought I was building a 64 bit library. It took a while to figure out that when you say --address-model=64
as a bjam command line parameter you have made a subtle mistake. The address-model
parameter must NOT have the --
prefix. Unfortunately bjam does not inform you when it sees the incorrect syntax.
您可以使用DUMPBIN程序来检查你的库提供的符号,与该连接器说是悬而未决的符号。我发现,库符号,用装饰__ thiscall
,而不是 __ CDECL
。这是结构不匹配的尖叫很好的线索。微软编译器使用 __ thiscall
函数调用协议的32位版本,但它使用 __ CDECL
64位构建。是的,微软的文档是有点弱在这里!
You can use the dumpbin program to check the symbols provided by your library, versus the symbols that the linker says are unresolved. I found that the library symbols were decorated with __thiscall
and not __cdecl
. This is a screaming good clue of the architecture mismatch. The Microsoft compiler uses the __thiscall
function call protocol for 32-bit builds, but it uses __cdecl
for 64-bit builds. Yes, the Microsoft documentation is a little weak here!!
要检查的.lib或.dll,看它是如何构建的,最好的办法是使用DUMPBIN程序。这里有一个例子:
The best way to check a .lib or .dll to see how it was built is to use the dumpbin program. Here's an example:
dumpbin /headers libboost_thread-vc100-mt-gd-1_45.lib | findstr machine
您将不得不调整库名以适应你当然链接的内容。这将毫无疑问地显示你的.lib或.dll是否是针对86(这是32位)或x64(64位)。
You'll have to adjust the library name to suit what you're linking of course. This will show you unambiguously whether the .lib or .dll is targeted for x86 (which is 32-bit) or x64 (64-bit).
这篇关于提高::线程的生成错误(无法链接的lib和放大器;&安培;无法解析的外部)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!