Ubuntu下使用boost例子

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. 例子

 
 
  1. #include <boost/thread.hpp>  
  2. #include <iostream>  
  3.   
  4. void task1() {   
  5.     // do stuff  
  6.     std::cout << "This is task1!" << std::endl;  
  7. }  
  8.   
  9. void task2() {   
  10.     // do stuff  
  11.     std::cout << "This is task2!" << std::endl;  
  12. }  
  13.   
  14. int main (int argc, char ** argv) {  
  15.     using namespace boost;   
  16.     thread thread_1 = thread(task1);  
  17.     thread thread_2 = thread(task2);  
  18.   
  19.     // do other stuff  
  20.     thread_2.join();  
  21.     thread_1.join();  
  22.     return 0;  
  23. }  
3. Makefile
g++ -I./inlcude -L./lib example.cpp -lboost_thread -o example
4.运行结果
This is task2!
This is task1!
  • 1
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值