1.安装boost的各类库sudo apt-get install libboost-all-dev,sudo apt-get install libbz2-dev
ios
2.从www.boost.org 下载boost源代码,解压bootstrap
3.在解压后的boost_1_51_0目录下给bootstrp.sh加上可执行权限,chmod a+x bootstrap.sh,执行./bootstrap.sh函数
4.而后执行刚生成的./bjam -s HAVE_ICU=1,而后编译大约一个多小时,根据机器不一样,时间会有差别测试
5.执行./bjam install --prefix=/usr,把编译结果安装到对应的文件夹里面,到此安装完成spa
测试aa.cpp线程
#define BOOST_THREAD_USE_LIB #include <iostream> #include <string> #include <boost/thread.hpp> using namespace std; using namespace boost; void threadRoutine(void) { boost::xtime time; time.nsec = 0; time.sec = 20; cout<<"线程函数作一些事情" << endl; boost::thread::sleep(time); } int main(void) { string str; cout<<"输入任意字符开始建立一个线程..." << endl; cin>>str; boost::thread t(&threadRoutine); t.join(); cout<<"输入任意字符结束运行..."<<endl; cin >> str; return 0; }
编译命令:gcc aa.cpp -lboost_thread -lpthread -lboost_filesystemcode
运行结果blog
输入任意字符开始建立一个线程...
q
线程函数作一些事情
输入任意字符结束运行...
ci
若是是在codeblok里面使用boost库的话,在工程->构建选项->连接器设置-> 其余连接器选项->加入-lboost_thread。
在搜索路径加入/usr/include/boost/ /usr/libget