2011-11-21 79 views
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 

我的窗口上使用mingw的4.5和g ++ 4.5.2。 Boost版本v1.4.8。

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

谢谢。

+2

它看起来像你没有与boost_thread链接。你能发布你的编译/链接命令吗? –

+0

这似乎是一个链接问题。你有没有告诉它链接到适当的库? – Kevin

+0

是的,我使用了g ++ -o tester.exe tester.c。我也用-I/location/to/boostfolder做了一次,但那也没用。 – user1058431

回答

3

它看起来像你没有链接到boost库。

因为它不是标准库,所以Boost并不带有窗口。您必须下载标题和库,然后将标题包含在项目中,并在编译时链接到库。既然你使用的是g ++,这意味着在你的编译命令中增加一个-l行。 -l行必须与您要使用的每个特定库一起使用,您不能只指定boost目录。

This page将帮助您开始使用Windows,this page将帮助您开始使用* nix平台。

一旦你在你的榜样编译提升,那么,你应该编译程序与

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

是的,我看过那个页面,虽然它根本没有帮助。我用bjam安装了它,并将头文件移到正确的位置以便找到它。但所有这些都没有做到。 – user1058431

+0

这不是标题问题。它一定可以在头文件中找到boost函数的声明。因为这是一个“未定义的参考”,这意味着它是一个链接问题。试着找出包含你试图调用的函数的函数定义的特定库,然后将-l/path/to/that /库添加到你的g ++命令中。 –

+0

您可能还会缺少-L参数,它告诉g ++在哪里查找库。请参阅我上面张贴的* nix链接中名为“将您的程序链接到Boost库”的部分。 –

0

确保你有正确关联的所有存储库。

尝试把此行第一,如果你的线程库是静态定义

#define BOOST_THREAD_USE_LIB 

此外,检查出this thread