我用 bjam 构建了我的 boost 库,然后移动了所有.a
文件到c:\Server\libs\boost_1_46_0\lib
如果我想编译我的程序,则会出现一些错误:
编译命令
g++ -Ic:\Server\libs\boost_1_46_0\ -Lc:\Server\libs\boost_1_46_0\lib\ -lboost_thread-mgw45-mt-1_46 -o try1 try1.cpp
错误
C:\Users\FEHERG~1\AppData\Local\Temp\ccB46To7.o:try1.cpp:(.text+0xe9): undefined
reference to `_imp___ZN5boost6thread4joinEv'
C:\Users\FEHERG~1\AppData\Local\Temp\ccB46To7.o:try1.cpp:(.text+0x120): undefine
d reference to `_imp___ZN5boost6threadD1Ev'
C:\Users\FEHERG~1\AppData\Local\Temp\ccB46To7.o:try1.cpp:(.text+0x138): undefine
d reference to `_imp___ZN5boost6threadD1Ev'
C:\Users\FEHERG~1\AppData\Local\Temp\ccB46To7.o:try1.cpp:(.text$_ZN5boost11this_
thread18interruptible_waitEm[boost::this_thread::interruptible_wait(unsigned lon
g)]+0x40): undefined reference to `_imp___ZN5boost11this_thread18interruptible_w
aitEPvNS_6detail7timeoutE'
C:\Users\FEHERG~1\AppData\Local\Temp\ccB46To7.o:try1.cpp:(.text$_ZN5boost6thread
C1IPFvvEEET_NS_10disable_ifINS_14is_convertibleIRS4_NS_6detail13thread_move_tIS4
_EEEEPNS0_5dummyEE4typeE[boost::thread::thread<void (*)()>(void (*)(), boost::di
sable_if<boost::is_convertible<void (*&)(), boost::detail::thread_move_t<void (*
)()> >, boost::thread::dummy*>::type)]+0x23): undefined reference to `_imp___ZN5
boost6thread12start_threadEv'
collect2: ld returned 1 exit status
谁能帮我这个问题有什么问题吗?
我遵循了这个教程: http://antonym.org/2009/05/threading-with-boost---part-i-creating-threads.html http://antonym.org/2009/05/threading-with-boost---part-i-creating-threads.html
所以这是来源:http://pastebin.com/YqCPLNwU http://pastebin.com/YqCPLNwU
UPDATE:
我认为错误不在库中,错误在库中。
我用 bjam 构建了它toolchain=gcc multithread
选项。
UPDATE
这是 objdumphttp://pastebin.com/4fpqYb7d http://pastebin.com/4fpqYb7d
UPDATE
我发现问题是链接器想要通过动态链接或类似的东西进行链接。
代码块、MinGW、Boost 和静态链接问题 https://stackoverflow.com/questions/3705563/code-blocks-mingw-boost-and-static-linking-issues
“杰克·凯利”说我需要添加#define BOOST_THREAD_USE_LIB
在我的源文件的开头。但这对我没有帮助。我如何静态链接库? (这-static
也没有帮助)