http://blog.csdn.net/dotphoenix/article/details/8459277
1. 安装boost库
sudo apt-get install libboost-all-dev
或者使用源代码编译:
sudo apt-get install python2.6-dev
sudo apt-get install libicu-dev
sudo apt-get install libbz2-dev
然后手动下载
http://www.bzip.org/1.0.5/bzip2-1.0.5.tar.gz
解压后安装.(执行./configure make make install三个命令)
然后访问下面地址下载
http://sourceforge.net/projects/libpng/files/zlib/1.2.5/zlib-1.2.5.tar.gz/download
同样进行解压安装
ldconfig
sudo apt-get update
wget -c ‘http://sourceforge.net/projects/boost/files/boost/1.50.0/boost_1_50_0.tar.bz2/download‘
tar xf download
cd boost_1_50_0
首先要编译生成boost安装工具bjam
进入boost目录执行:
./bootstrap.sh
然后执行刚生成的
./bjam -s HAVE_ICU=1
编译开始,大约半小时,全部编译结束。
./bjam install --prefix=/usr
将当前目录下编译好的头文件安装到相应位置:在/usr/include下有头文件夹boost,在/usr/lib下有boost的库
2. 例子
- #include <boost/thread.hpp>
- #include <iostream>
- void task1() {
- // do stuff
- std::cout << "This is task1!" << std::endl;
- }
- void task2() {
- // do stuff
- std::cout << "This is task2!" << std::endl;
- }
- int main (int argc, char ** argv) {
- using namespace boost;
- thread thread_1 = thread(task1);
- thread thread_2 = thread(task2);
- // do other stuff
- thread_2.join();
- thread_1.join();
- return 0;
- }
3. Makefile
g++ -I./inlcude -L./lib example.cpp -lboost_thread -o example
4.运行结果
This is task2!
This is task1!
Ubuntu下使用boost例子
时间: 2024-10-12 07:58:31