Ubuntu18.04安装boost1.48.0

https://www.cnblogs.com/afan/archive/2013/05/04/3060386.html
Ubuntu18.04安装boost1.48.0

参考地址:

  1. http://www.mamicode.com/info-detail-932057.html[1]
  2. http://blog.csdn.net/yhrun/article/details/8099630[2]
    环境: ubuntu18.04 g++4.8 boost1.48.0

Ubuntu18.04安装boost1.48.0
安装个boost依赖库
安装boost库
1 解压压缩包
2 执行配置文件
3 编译boost库
4 安装boost库
5 设置动态库权限

boost_thread 使用测试

1 安装4个boost依赖库:

apt-get install mpi-default-dev  #安装mpi库
apt-get install libicu-dev  #支持正则表达式的UNICODE字符集
apt-get install python-dev #需要python的话
apt-get install libbz2-dev #如果编译出现错误:bzlib.h: No such file or directory

2 安装boost库

2.1 解压压缩包

从boost官网下载 boost_1_48_0.tar.gz (该例子将压缩包放在Downloads中),然后解压:

tar -xzvf boost_1_48_0.tar.gz

2.2 执行配置文件

cd boost_1_48_0
sudo ./bootstrap.sh #默认路径为/usr/local

在当前目录下生成b2和bjam可执行文件(两者一样),终端结果:

2.3 编译boost库

sudo ./b2 -a -sHAVE_ICU=1 #大约30分钟

出现的错误及解决办法:

boost_thread库安装失败

错误1:
 结果:  
原因:
g++ 4.7以上的版本不能使能boost1.48及以下的版本。
解决办法:修改 ./boost/config/stdib/libstdcpp3.hpp 文件

错误2:
结果:

原因:TIME_UTC定义冲突
解决办法:将目录 boost_1_48_0 中所有TIME_UTC 换成XTIME_UTC

locale库安装失败
错误 :

./libs/locale/src/icu/formatter.cpp中的第61行出现format函数有二义性;
原因:安装的libicu-dev库与原始的库冲突
解决办法:

sudo apt-get remove libicu-dev
成功结果:

2.4 安装boost库

sudo ./b2 install

2.5 设置动态库权限

将新安装的动态库,设置成系统共享:

sudo ldconfig /usr/local/lib

成功结果:没有出现 skip .. targets等非updated关键字

3 boost_thread 使用测试

testBoost.cpp

#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;
}

编译运行g++ -o testBoost testBoost.cpp -lboost_thread其中boost 库需放在.c或.cpp之后,否则链接不能通过,编译可以通过[1]

成功结果:

$ ./testBoost
This is task1!
This is task2!
————————————————

最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

友情链接更多精彩内容