g ++包括boost库 [英] g++ including boost library
问题描述
我使用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
引用`_imp___ZN5boost6thread4joinEv'
C:\ Users \ FEHERG〜1 \AppData\Local \Temp\ccB46To7.o:try1.cpp :(。text + 0x120):undefine
d对`_imp___ZN5boost6threadD1Ev'的引用
C:\ Users \ FEHERG〜1 \AppData\Local \Temp\ccB46To7.o:try1.cpp :(。text + 0x138):undefine
d引用`_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):对_imp___ZN5boost11this_thread18interruptible_w
aitEPvNS_6detail7timeoutE'
的未定义引用C:\Users\FEHERG〜1\AppData\Local\ Temp \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\' ,boost :: di
sable_if< boost :: is_convertible< void(*&)(),boost :: detail :: thread_move_t< void(*
)()> >,boost :: thread :: dummy *> :: type)] + 0x23):未定义引用到_imp___ZN5
boost6thread12start_threadEv'
collect2:ld返回1退出状态
有人可以帮我解决这个问题吗?
我遵循本教程: http://antonym.org/2009/05/threading-with-boost---part-i-creating-threads.html
<所以这是来源: http://pastebin.com/YqCPLNwU
更新:
我认为错误不在库中,错误在库中。
i用bjam用 toolchain = gcc multithread
选项构建它。
$ b
UPDATE
这里是objdump http://pastebin.com/ 4fpqYb7d
更新
我发现问题在于链接器想链接到动态链接或类似的东西。
那里Jack Kelly说我需要在源文件的开头添加
#define BOOST_THREAD_USE_LIB
。但这对我没有帮助。我怎样才能静态链接一个库? ( -static
没有帮助) lboost_thread-mgw45-mt-1_46选项到命令行末尾(在try1.cpp之后)。 (来自聊天) i builded my boost library with bjam, and then moved all the .a
files into c:\Server\libs\boost_1_46_0\lib
if i want to compile my program there is some error:
the compile command
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
the errors
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
can anybody help me what is the problem in this problem?
i followed this tutorial: http://antonym.org/2009/05/threading-with-boost---part-i-creating-threads.html
so this is the source: http://pastebin.com/YqCPLNwU
UPDATE:
i think the error is not lining the library, the error is in the library.
i built it with bjam with toolchain=gcc multithread
options.
UPDATE
here is the objdump http://pastebin.com/4fpqYb7d
UPDATE
i found that the problem is that the linker wants to link with dynamic linking or something like this.
Code Blocks, MinGW, Boost, and static linking issues
there "Jack Kelly" says that i need to add #define BOOST_THREAD_USE_LIB
at the beginning of my source file. but this not helps to me. how can i link a library statically? (the -static
not helped as well)
Move the -lboost_thread-mgw45-mt-1_46 option to the end of the command line (after try1.cpp). (From chat.)
这篇关于g ++包括boost库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!