Linux编译安装boost

本文详细介绍了在Linux环境下编译安装Boost库的步骤,包括安装依赖、下载源代码、配置编译参数及安装过程。同时,提供了一个使用Boost线程库的测试示例,展示了如何在CodeBlocks中配置Boost库。

1.安装boost的各种库sudo apt-get install libboost-all-dev,sudo apt-get install libbz2-dev

2.从www.boost.org 下载boost源代码,解压

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,把编译结果安装到对应的文件夹里面,到此安装完成

测试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_filesystem

运行结果

输入任意字符开始创建一个线程...
q
线程函数做一些事情
输入任意字符结束运行...

如果是在codeblok里面使用boost库的话,在工程->构建选项->链接器设置-> 其他链接器选项->加入-lboost_thread。

在搜索路径加入/usr/include/boost/ /usr/lib

 

posted on 2013-07-15 12:08  HACKMIND 阅读( ...) 评论( ...) 编辑 收藏

转载于:https://www.cnblogs.com/desheng-Win/p/3190917.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值