Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/159.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ Boost线程错误:未定义引用 #包括 #包括 void hello() { std::cout_C++_Boost_Boost Thread - Fatal编程技术网

C++ Boost线程错误:未定义引用 #包括 #包括 void hello() { std::cout

C++ Boost线程错误:未定义引用 #包括 #包括 void hello() { std::cout,c++,boost,boost-thread,C++,Boost,Boost Thread,许多boost库都是在头文件中完全实现的。boost.thread不是。它似乎没有在boost线程库中链接。请检查链接器搜索路径。或者,正如Stargazer712在OP上的评论所说,检查安装。您应该在lib目录中看到类似libboost_thread-gcc-xxx-1_nn.o的内容。如果是这样,请尝试在链接步骤中显式引用它(类似于-L-lboost-thread-gcc-xx-1\n)。如果不是这样,则显然没有完整的安装。添加编译选项 /usr/include/boost/thread/p

许多boost库都是在头文件中完全实现的。boost.thread不是。它似乎没有在boost线程库中链接。请检查链接器搜索路径。或者,正如Stargazer712在OP上的评论所说,检查安装。您应该在lib目录中看到类似libboost_thread-gcc-xxx-1_nn.o的内容。如果是这样,请尝试在链接步骤中显式引用它(类似于
-L-lboost-thread-gcc-xx-1\n
)。如果不是这样,则显然没有完整的安装。

添加编译选项

/usr/include/boost/thread/pthread/mutex.hpp:40: undefined reference to
   `boost::thread_resource_error::thread_resource_error()'
/usr/include/boost/thread/pthread/mutex.hpp:40: undefined reference to 
   `boost::thread_resource_error::~thread_resource_error()'
/usr/include/boost/thread/pthread/mutex.hpp:40: undefined reference to 
   `typeinfo for boost::thread_resource_error'
./src/thread.o: In function `condition_variable':
/usr/include/boost/thread/pthread/condition_variable_fwd.hpp:33: 
  undefined reference to `boost::thread_resource_error::thread_resource_error()'
/usr/include/boost/thread/pthread/condition_variable_fwd.hpp:33: 
  undefined reference to `boost::thread_resource_error::~thread_resource_error()'
/usr/include/boost/thread/pthread/condition_variable_fwd.hpp:33: \
  undefined reference to `typeinfo for boost::thread_resource_error'
./src/thread.o: In function `thread_data_base':
/usr/include/boost/thread/pthread/thread_data.hpp:54: 
  undefined reference to `vtable for boost::detail::thread_data_base'
./src/thread.o: In function `thread<void (*)()>':
/usr/include/boost/thread/detail/thread.hpp:188: 
  undefined reference to `boost::thread::start_thread()'
./src/thread.o: In function `~thread_data':
/usr/include/boost/thread/detail/thread.hpp:40: 
  undefined reference to `boost::detail::thread_data_base::~thread_data_base()'
/usr/include/boost/thread/detail/thread.hpp:40: undefined reference to 
  `boost::detail::thread_data_base::~thread_data_base()'
-L-lboost-thread-gcc-xx-1\n

gregg的答案是正确的!

使用mt标记编译,即
-lboost\u thread-mt

我在编译povray 3.7时在centos 6.5上遇到了类似的问题,这就解决了它-只需在
生成文件中添加
-lboost\u thread-mt
我有同样的问题,但是-lboost\u thread-mt现在不推荐使用请参见askubuntu.com.in取而代之的是,您现在想要在makefile(至少对于linux)中实现的是:


Boost只是让您有责任链接到系统的线程库。

我也有同样的错误。我用-lboost\u thread编译它,而不是

-lpthread -lboost_thread ...
试一试


听起来您的系统上没有正确安装boost,但我的
#include#include#include使用名称空间std;使用名称空间boost;int main(){string str1;cin>>str1;//string str1(“hello world!”;to_upper(str1);couti发现了它我需要在ubuntuThis中安装libboost线程包,它在我的boost线程系统中编译和运行良好。因此我必须同意这可能是您的安装有问题。另外,感谢您教我一种使用boost线程的新方法。我一直在使用带有运算符()的类定义——这是我从阅读资料中得到的解释。我遇到了一个类似的问题,并确定这是因为我的系统上安装了两个Boost。删除一个会导致代码编译。希望这对其他解决方案没有帮助的人有所帮助。作为记录,它是-lboost_线程。请参阅@Josh:感谢您的输入。see和.or
-lboost_thread-mgwXX-mt-N_NN
其中XX是您的mgw版本,通常只有前两个(4.7.1=>47)和Ns是您的boost版本,同样是前两个(boost_1_55_0=>1_55),所以最后一个可能看起来像:boost::detail::thread\mgw47-mt-1\u 55
前面已经提供了类似的答案。put-lboost\u thread最终会删除警告:对`boost::detail::thread\u data\u base::~thread\u data\u base()的未定义引用
-L<path_to_lib> -lboost-thread-gcc-xx-1_nn
-lpthread -lboost_thread ...
g++ -pthread -lboost_thread X.cpp
g++ X.cpp -pthread -lboost_thread