g++包括升压库

发布于 2024-10-21 20:09:12 字数 2435 浏览 1 评论 0原文

我用 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://pastebin.com/YqCPLNwU

更新:

我认为错误不是在库中,错误是在图书馆里。 我用 bjam 和 toolchain=gcc multithread 选项构建了它。

更新

这里是objdump http://pastebin.com/4fpqYb7d

更新

我发现问题是链接器想要通过动态链接或类似的东西进行链接。

代码块、MinGW、Boost 和静态链接问题

“Jack Kelly”说我需要在源文件的开头添加#define BOOST_THREAD_USE_LIB。但这对我没有帮助。我如何静态链接库? (-static 也没有帮助)

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)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

ㄟ。诗瑗 2024-10-28 20:09:12

在开头添加 #define BOOST_THREAD_USE_LIB 有效。

请记住还链接错误中列出的 boost 库(在我的例子中是 boost 系统)。

adding #define BOOST_THREAD_USE_LIB at the beginning works.

Remember to link also boost libs listed in the errors (boost system in my case).

刘备忘录 2024-10-28 20:09:12

将 -lboost_thread-mgw45-mt-1_46 选项移至命令行末尾(在 try1.cpp 之后)。 (来自聊天。

Move the -lboost_thread-mgw45-mt-1_46 option to the end of the command line (after try1.cpp). (From chat.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文