c ++链接失败,未定义引用libboost_thread [英] c++ linking failed with undefined reference to libboost_thread

查看:944
本文介绍了c ++链接失败,未定义引用libboost_thread的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

刚开始使用boost线程的多线程;我有一个Hello World类型的程序,在链接到线程库失败。以下是终端窗口输出:

Just getting started with multithreading using boost threads; I have a Hello World type program which fails during linking to the thread library. The following is the terminal window output:

 g++ -Wall -I/usr/include HelloWorld.cpp -L/usr/local/lib -pthread -lboost_thread -lrt -lboost_system
/tmp/ccTKHnfd.o: In function `main':
HelloWorld.cpp:(.text+0x4a): undefined reference to `boost::thread::join()'
HelloWorld.cpp:(.text+0x5b): undefined reference to `boost::thread::~thread()'
HelloWorld.cpp:(.text+0x70): undefined reference to `boost::thread::~thread()'
/tmp/ccTKHnfd.o: In function `boost::thread::thread<void (*)()>(void (*)(), boost::disable_if<boost::is_convertible<void (*&)(), boost::detail::thread_move_t<void (*)()> >, boost::thread::dummy*>::type)':
HelloWorld.cpp: (.text._ZN5boost6threadC2IPFvvEEET_NS_10disable_ifINS_14is_convertibleIRS4_NS_6detail13thread_move_tIS4_EEEEPNS0_5dummyEE4typeE[_ZN5boost6threadC5IPFvvEEET_NS_10disable_ifINS_14is_convertibleIRS4_NS_6detail13thread_move_tIS4_EEEEPNS0_5dummyEE4typeE]+0x23): undefined reference to `boost::thread::start_thread()'
collect2: ld returned 1 exit status

我安装boost dev库1.48使用aptitude并相信我使用所有正确的标志编译器。我缺少什么?我的gcc是4.6.3。先感谢您的帮助

I installed boost dev libraries 1.48 using aptitude and believe I am using all the right flags for the compiler. What am I missing? My gcc is 4.6.3. Thanks in advance for your help

推荐答案

看起来您找不到libboost_thread.so或libboost_thread.a。
你的/ usr / local / lib里实际上有什么?你可以做

Looks like you can't find libboost_thread.so or libboost_thread.a. What is actually there in your /usr/local/lib? You can do

ls / usr / local / lib | grep线程。如果没有看到libboost_thread.so或libboost_thread.a,那么这就解释了为什么你有未定义的引用 - 实现这些功能的对象实际上并不存在。

ls /usr/local/lib | grep thread. If you don't see libboost_thread.so or libboost_thread.a, then that explains why you have the undefined reference - the object implementing these functions isn't actually there.

此外,如果您没有看到libboost_thread.so,但您确实看到libboost_thread.so.3.6或某事(表示特定版本),那么您可以执行以下两种操作之一:直接链接到该链接或创建一个符号链接即须藤LN -s /usr/local/lib/libboost_thread.so.3.6 /usr/local/lib/libboost_thread.so

Additionally, if you don't see libboost_thread.so but you do see libboost_thread.so.3.6 or something (which denotes a specific version), then you can do one of two things: either link to that directly or create a symbolic link (i.e. sudo ln -s /usr/local/lib/libboost_thread.so.3.6 /usr/local/lib/libboost_thread.so)

这篇关于c ++链接失败,未定义引用libboost_thread的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆