C++ 如何编译Boost多线程程序?

C++ 如何编译Boost多线程程序?,c++,multithreading,boost,C++,Multithreading,Boost,我安装了boost库。没有多线程,一切都正常。 如何编译这个测试程序 #include <boost/thread/thread.hpp> #include <iostream> using namespace std; void hello_world() { cout << "I'm new thread!" << endl; } int main(int argc, char* argv[]) { boost::thr

我安装了boost库。没有多线程,一切都正常。 如何编译这个测试程序

#include <boost/thread/thread.hpp>
#include <iostream>
using namespace std; 

void hello_world() {
  cout << "I'm new thread!" << endl;
}

int main(int argc, char* argv[]) {     
  boost::thread my_thread(&hello_world);
  my_thread.join();

  return 0;
}

您还需要链接到Boost线程库:

g++ -I/home/user/boost/include testc.cpp -L/home/user/boost/lib -lboost_thread

(假设库位于
/home/user/boost/lib
中)

和类似“boost::system::generic\u category()”的符号可能来自boost\u系统库。谢谢您的回答。我加上:
-lboost\u系统
,一切正常
g++-I/home/user/boost/include testc.cpp-L/home/user/boost/lib-lboost\u thread-lboost\u system
g++-static-pthread-I/home/user/boost/include testc.cpp-L/home/user/boost/lib-lboost\u thread-lboost\u system
g++ -I/home/user/boost/include testc.cpp -L/home/user/boost/lib -lboost_thread