> sudo apt-get -y install python-dev libxml2-dev libxslt-dev libbz2-dev
> wget https://sourceforge.net/projects/boost/files/boost/1.78.0/boost_1_78_0.tar.gz/download
> tar zxvf boost_1_78_0.tar.gz
> cd boost_1_78_0
> ./bootstrap.sh --prefix=/usr/local/boost
> ./b2
> sudo ./b2 install
> sudo vim /etc/profile
export CPLUS_INCLUDE_PATH=$CPLUS_INCLUDE_PATH:/usr/local/boost/include
export LIBRARY_PATH=$LIBRARY_PATH:/usr/local/boost/lib
> source /etc/profile
> sudo vim /etc/ld.so.conf
/usr/local/boost/lib
> sudo ldconfig
output
> g++ test_boost.cc
> ./a.out
105700
1_57
linux
GNU C++ version 7.5.0
GNU libstdc++ version 20191114
#include <boost/thread/thread.hpp> //包含boost头文件
#include <iostream>
#include <cstdlib>
using namespace std;
volatile bool isRuning = true;
void func1()
{
static int cnt1 = 0;
while(isRuning)
{
cout << "func1:" << cnt1++ << endl;
sleep(1);
}
}
void func2()
{
static int cnt2 = 0;
while(isRuning)
{
cout << "func2:" << cnt2++ << endl;
sleep(2);
}
}
int main()
{
boost::thread thread1(&func1);
boost::thread thread2(&func2);
system("read");
isRuning = false;
thread2.join();
thread1.join();
cout << "exit" << endl;
return 0;
}
g++ test_boost_thread.cc -o test_boost_thread -lboost_thread -lpthread -lboost_system
error: sh: 1: read: arg count