【编译Boost库】Linux下如何编译和安装Boost库

前言

编译比特币钱包时,需要依赖Boost库,由于编译时间较长,在“试一试”中浪费好长时间,所以把可以成功的过程记录下来吧。

下载Boost安装包

  • 通过wget工具下载
wget https://dl.bintray.com/boostorg/release/1.64.0/source/boost_1_64_0.tar.gz

反正我没成功下载下来~

  • 手动下载安装包
    在上述地址上下载到本地,再上传到服务器

解压缩

[root@bogon software]# tar zxvf boost_1_64_0.tar.gz

编译和安装

先进入解压缩后的目录:

[root@bogon software]# cd boost_1_64_0

然后运行bootstrap.sh脚本并设置相关参数:

[root@bogon boost_1_64_0]# ./bootstrap.sh --with-libraries=all --with-toolset=gcc

--with-libraries指定编译哪些boost库all的话就是全部编译,只想编译部分库的话就把库的名称写上,之间用 , 号分隔即可,可指定的库有以下几种:

库名 说明
    atomic
    chrono
    context
    coroutine
    date_time
    exception
    filesystem
    graph
图组件和算法
    graph_parallel
    iostreams
    locale
    log
    math
    mpi
用模板实现的元编程框架
    program_options
    python
把C++类和函数映射到Python之中
    random
    regex
正则表达式库
    serialization
    signals
    system
    test
    thread
可移植的C++多线程库
    timer
    wave

--with-toolset指定编译时使用哪种编译器,Linux下使用gcc即可,如果系统中安装了多个版本的gcc,在这里可以指定gcc的版本,比如--with-toolset=gcc-4.4

命令执行完成后看到显示如下即为成功:

Building Boost.Build engine with toolset gcc... tools/build/src/engine/bin.linuxx86_64/b2
Detecting Python version... 2.6
Detecting Python root... /usr
Unicode/ICU support for Boost.Regex?... not found.
Generating Boost.Build configuration in project-config.jam...

Bootstrapping is done. To build, run:

    ./b2

To adjust configuration, edit 'project-config.jam'.
Further information:

   - Command line help:
     ./b2 --help

   - Getting started guide: 
     http://www.boost.org/more/getting_started/unix-variants.html

   - Boost.Build documentation:
     http://www.boost.org/build/doc/html/index.html

执行以下命令开始进行boost的编译:

[root@bogon boost_1_64_0]# ./b2 toolset=gcc

编译的时间大概要10多分钟,耐心等待,结束后会有以下提示:

ln-UNIX stage/lib/libboost_wave.so
...failed updating 56 targets...
...skipped 6 targets...
...updated 1081 targets...

最后执行以下命令开始安装boost:

[root@bogon boost_1_64_0]# ./b2 install --prefix=/usr

--prefix=/usr用来指定boost的安装目录,不加此参数的话默认的头文件在/usr/local/include/boost目录下,库文件在/usr/local/lib/目录下。这里把安装目录指定为--prefix=/usr则boost会直接安装到系统头文件目录和库文件目录下,可以省略配置环境变量。

安装完毕后会有以下提示:

...failed updating 56 targets...
...skipped 6 targets...
...updated 13610 targets...

最后需要注意,如果安装后想马上使用boost库进行编译,还需要执行一下这个命令:

[root@bogon boost_1_64_0]# ldconfig

更新一下系统的动态链接库。

再次编译比特币钱包即可。

猜你喜欢

转载自blog.csdn.net/changqing5818/article/details/80462178