编译期间提升未定义的引用

发布于 2024-12-17 10:24:44 字数 1297 浏览 0 评论 0原文

我在尝试从文档编译一个简单的测试程序时遇到编译错误。

C:\DOCUME~1\A\LOCALS~1\Temp\ccRsXzHu.o:tester.cpp:(.text+0xa6): undefined reference to     `_imp___ZN5boost6thread4joinEv'
C:\DOCUME~1\A\LOCALS~1\Temp\ccRsXzHu.o:tester.cpp:(.text+0xb4): undefined reference to     `_imp___ZN5boost6threadD1Ev'
C:\DOCUME~1\A\LOCALS~1\Temp\ccRsXzHu.o:tester.cpp:(.text+0xcf): undefined reference to     `_imp___ZN5boost6threadD1Ev'
C:\DOCUME~1\A\LOCALS~1\Temp\ccRsXzHu.o:tester.cpp:    (.text$_ZN5boost11this_thread18interruptible_waitEy[boost::this_thread::interruptible_wait(    unsigned long long)]+0x4a): undefined reference to     `_imp___ZN5boost11this_thread18interruptible_waitEPvNS_6detail7timeoutE'
C:\DOCUME~1\A\LOCALS~1\Temp\ccRsXzHu.o:tester.cpp:     (.text$_ZN5boost6threadC1IPFvvEEET_NS_10disable_ifINS_14is_convertibleIRS4_NS_6detail13thre    ad_move_tIS4_EEEEPNS0_5dummyEE4typeE[boost::thread::thread<void (*)()>(void (*)(),     boost::disable_if<boost::is_convertible<void (*&)(), boost::detail::thread_move_t<void (*)()> >, boost::thread::dummy*>::type)]+0x23): undefined reference to     `_imp___ZN5boost6thread12start_threadEv'
collect2: ld returned 1 exit status

我在 Windows 上使用 mingw 4.5 和 g++ 4.5.2。升压版本v1.4.8。

我希望有人能帮助我解决这个问题。

谢谢。

I am getting a compile error trying to compile a simple tester program from the documentation.

C:\DOCUME~1\A\LOCALS~1\Temp\ccRsXzHu.o:tester.cpp:(.text+0xa6): undefined reference to     `_imp___ZN5boost6thread4joinEv'
C:\DOCUME~1\A\LOCALS~1\Temp\ccRsXzHu.o:tester.cpp:(.text+0xb4): undefined reference to     `_imp___ZN5boost6threadD1Ev'
C:\DOCUME~1\A\LOCALS~1\Temp\ccRsXzHu.o:tester.cpp:(.text+0xcf): undefined reference to     `_imp___ZN5boost6threadD1Ev'
C:\DOCUME~1\A\LOCALS~1\Temp\ccRsXzHu.o:tester.cpp:    (.text$_ZN5boost11this_thread18interruptible_waitEy[boost::this_thread::interruptible_wait(    unsigned long long)]+0x4a): undefined reference to     `_imp___ZN5boost11this_thread18interruptible_waitEPvNS_6detail7timeoutE'
C:\DOCUME~1\A\LOCALS~1\Temp\ccRsXzHu.o:tester.cpp:     (.text$_ZN5boost6threadC1IPFvvEEET_NS_10disable_ifINS_14is_convertibleIRS4_NS_6detail13thre    ad_move_tIS4_EEEEPNS0_5dummyEE4typeE[boost::thread::thread<void (*)()>(void (*)(),     boost::disable_if<boost::is_convertible<void (*&)(), boost::detail::thread_move_t<void (*)()> >, boost::thread::dummy*>::type)]+0x23): undefined reference to     `_imp___ZN5boost6thread12start_threadEv'
collect2: ld returned 1 exit status

I am using mingw 4.5 and g++ 4.5.2 on windows. Boost version v1.4.8.

I hope someone can help me solve this problem.

Thanks.

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

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

发布评论

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

评论(2

朦胧时间 2024-12-24 10:24:44

您似乎没有链接到 boost 库。

Boost 不随 Windows 一起提供,因为它不是标准库。您必须下载标头和库,然后将标头包含在项目中并在编译时链接到库。由于您使用的是 g++,这意味着在编译命令中添加 -l 行。 -l 行必须与您想要使用的每个特定库一起使用,您不能只指定 boost 目录。

此页面将帮助您开始使用 Windows,并且< href="http://www.boost.org/doc/libs/1_48_0/more/getting_started/unix-variants.html" rel="nofollow">此页面将为您提供帮助开始在 *nix 平台上使用。

一旦你编译了 boost,那么在你的例子中,你应该用

g++ -o tester.exe -Lpath/to/boost/libraries/ -lboost_thread tester.c

It looks like you aren't linking to the boost libraries.

Boost doesn't come with windows since it isn't a standard library. You've got to download the headers and libraries, then include the headers in your project and link to the libraries at compile time. Since you're using g++, this means adding a -l line to your compile command. The -l line must be used with each specific library you want to use also, you can't just specify the boost directory.

This page will help you get started on Windows and this page will help you get started on *nix platforms.

Once you've compiled boost, then in your example, you should compile your program with

g++ -o tester.exe -Lpath/to/boost/libraries/ -lboost_thread tester.c
灵芸 2024-12-24 10:24:44

确保您已正确链接所有库。

如果您的线程库是静态定义的,请尝试将此行放在第一位

#define BOOST_THREAD_USE_LIB

另外,请查看 这个线程

Make sure you've got all your libraries linked properly.

Try putting this line first if your thread library is statically defined

#define BOOST_THREAD_USE_LIB

Also, check out this thread.

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