Linux【8】-软件管理-9-软件安装6-linux下编译安装boost库

安装seshat的过程中,提示我要安装boost。boost 是什么?我也不关心哒

boost下载地址: https://www.boost.org/users/download/

1、下载并解压boost 1.58 源代码

可以去boost的官网下载,这里提供一个下载地址

wget http://jaist.dl.sourceforge.net/project/boost/boost/1.58.0/boost_1_58_0.tar.bz2

解压

tar -xjf boost_1_58_0.tar.bz2

2、运行bootstrap.sh

bootstrap.sh是用来检查安装环境的,如果报错了,看一下是缺少了什么,安装一下即可(g++)。

cd boost_1_58_0/
./bootstrap.sh

运行完成之后会在当前目录生成一些文件,用于下一步安装

3、使用b2进行构建

b2是上一步成功后生成的,使用它来进行构建boost库。

sudo ./b2

这里也可能遇到错误,比如没有bzlib.h这个头文件的。

cc.compile.c++ bin.v2/libs/iostreams/build/gcc-4.9.2/release/link-static/threading-multi/bzip2.o
libs/iostreams/src/bzip2.cpp:20:56: fatal error: bzlib.h: 没有那个文件或目录
 #include "bzlib.h"  // Julian Seward's "bzip.h" header.
                                                    ^
compilation terminated.

解决办法也是很简单的,执行下面的语句(前提是debina系的linux发行版,或者安装了apt-get)

sudo apt-get install libbz2-dev 

构建成功的提示

The Boost C++ Libraries were successfully built!

The following directory should be added to compiler include paths:

/home/o/Boost库/boost_1_58_0

The following directory should be added to linker library paths:

/home/o/Boost库/boost_1_58_0/stage/lib

上面两句的意思是提示你编译使用了boost库的代码的时候指定的include目录和lib目录位置。

4、安装boost库到指定目录

第三步骤只是说了构建的情况,其实这已经可以用了。如果想安装boost库到指定目录,比如说usr/local目录,可以使用下面的命令来进行。

sudo ./b2 --prefix=/usr/local/boost install

安装以后编译代码的时候还是要指定目录,可以将它添加到环境变量CPLUS_INCLUDE_PATH和LIBRARY_PATH中去。

export CPLUS_INCLUDE_PATH=/usr/local/boost/include
export LIBRARY_PATH=/usr/local/boost/lib

这只是临时的,乐意的可以写入/etc/profile文件中。

5、测试一下

先写一个简单的获取当前日期的小程序

代码

#include <boost/date_time/gregorian/gregorian.hpp> 
#include <iostream> 
int main() 
{ 
    boost::gregorian::date d(boost::gregorian::day_clock::local_day());
    std::cout << d.year() << d.month() <<d.day() << std::endl; 
}
编译运行

g++ -I /usr/local/boost/include -L /usr/local/boost/lib boost.cpp -o boost

 ./boost 

2015Jul9

xerces 安装

http://mirrors.tuna.tsinghua.edu.cn/apache//xerces/c/3/sources/xerces-c-3.2.0.tar.gz
gunzip xerces-c-3.2.0.tar.gz

 tar -xvf xerces-c-3.2.0.tar
 cd xerces-c-3.2.0/
 ./configure --prefix=/usr 
  make all
 make install

vim /etc/profile

添加:

export XERCESCROOT=/data/sam/project/xerces-c-3.2.0

export LD_LIBRARY_PATH=/usr/lib

source /etc/profile

参考资料

https://www.cnblogs.com/findumars/p/6253092.html

药企,独角兽,苏州。团队长期招人,感兴趣的都可以发邮件聊聊:tiehan@sina.cn
个人公众号,比较懒,很少更新,可以在上面提问题,如果回复不及时,可发邮件给我: tiehan@sina.cn