您的位置:首页 > 运维架构 > Linux

Linux系统下Boost库编译与安装

2017-08-30 14:53 357 查看

Linux系统下Boost库编译与安装

类库下载

可以通过以下链接方式获得
官网下载链接 : http://www.boost.org

github源代码https://github.com/boostorg/boost

由于Boost大量使用了C++的高级特性,因此不同版本的Boost库需要的编译器也不同,组件对编译器支持也不同,建议使用前更新编译器版本。本文使用的编译器为 gcc version 5.3.1、boost1.64

快捷安装

下载解压后,在linux中进入boost 文件夹中(安装前为文件夹添加权限,防止权限问题导致失败)

依次运行文件夹下可执行文件:

./bootstrap.sh  // 编译前的配置工作,脚本内包含配置信息
./b2 install    // 编译安装Boost


上述情况将直接编译安装release版本的库文件,并把头文件安装到/usr/local/include中,库文件安装到/usr/local/lib下。

完全安装

默认快捷安装时,使用release模式,需要安装全部boost版本时可以通过使用buildtype选项指定编译类型,如指定完整编译类型

./boostrap.sh
./b2 --buildtype=complete install


该方式将进行完整编译,安装所有调试版、发行版的静态、动态库。

部分安装

很多情况下,我们只需要boost 库的部分内容,完整编译费时费力,因此可以通过编译选项自行选择需要编译安装的库,依然是./b2执行文件使用

./b2 --show-libraries   // 显示需要编译才能使用的库

// 运行结果:
The following libraries require building:
- atomic
- chrono
- container
- context
- coroutine
- coroutine2
- date_time
- exception
- fiber
- filesystem
- graph
- graph_parallel
- iostreams
- locale
- log
- math
- metaparse
- mpi
- program_options
- python
- random
- regex
- serialization
- signals
- system
- test
- thread
- timer
- type_erasure
- wave
// 仅编译单个库时,可以通过with/without添加删除
./b2 --with-thread --buildtype=complete install

// 运行结果:
The Boost C++ Libraries
8da6
were successfully built!

The following directory should be added to compiler include paths:

/Users/lwq/Desktop/Boost/boost_1_64_0

The following directory should be added to linker library paths:

/Users/lwq/Desktop/Boost/boost_1_64_0/stage/lib


可以看到,编译结果被放到了当前目录下,通过命令:

./bootstrap --help
./b2 --help


或通过Boost文档,可以查询编译主要选项,指定安装的路径、版本。

本人的安装选项为
sudo ./b2 link=static install #编译安装所有静态库


环境验证

通过简单的Boost应用程序验证开发环境。

在头文件<boost/version.hpp> 中定义了两个宏:程序库版本号

#include <iostream>

// Boost测试程序
#include <boost/version.hpp>
#include <boost/config.hpp>

int main()
{
std::cout << "版本号(数字):" << BOOST_VERSION << std::endl;
std::cout << "版本号(字符串):" << BOOST_LIB_VERSION << std::endl;
std::cout << "操作系统:" << BOOST_PLATFORM << std::endl;
std::cout << "编译器:" << BOOST_COMPILER << std::endl;
std::cout << "标准库:" << BOOST_STDLIB << std::endl;

return 0;
}


通过直接输出相关信息,检查能否正确使用Boost文件即可。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: