Ubuntu下编译boost(附Eclipse静态链接库设置)
这不是一篇向导,全面的向导请看 这里 (http://goo.gl/XcAf)。这仅是一篇笔记。这里用 bjam方式 进行编译。
- 下载boost。(http://cdnetworks-kr-1.dl.sourceforge.net/project/boost/boost/1.42.0/boost_1_42_0.tar.bz2)
- 解压到指定文件夹,我是将它解压到根目录下的一个sourcecode文件夹下。
/home/volnet/sourcecode/boost_1_42_0
- 启动终端(ctrl+f2,输入“gnome-terminal”)。生成bjam脚本。
./bootstrap.sh --prefix=/home/volnet/sourcecode/boost_install如果不带--prefix参数的话(推荐),默认的路径是/usr/local/include和/usr/local/lib./bootstrap.sh使用--help参数可以查看帮助,用-h可以查看简要帮助。./bootstrap.sh --help生成脚本bjam,已经存在的脚本将被自动备份。
volnet@Ubuntu :~/sourcecode/boost_1_42_0$ ./bootstrap.sh --prefix=/home/volnet/sourcecode/boost_install/ Building Boost.Jam with toolset gcc... tools/jam/src/bin.linuxx86/bjam Detecting Python version... 2.6 Detecting Python root... /usr Unicode/ICU support for Boost.Regex?... /usr Backing up existing Boost.Build configuration in project-config.jam.4 Generating Boost.Build configuration in project-config.jam... Bootstrapping is done. To build, run: ./bjam To adjust configuration, edit 'project-config.jam'. Further information: - Command line help: ./bjam --help - Getting started guide: http://www.boost.org/more/getting_started/unix-variants.html - Boost.Build documentation: http://www.boost.org/boost-build2/doc/html/index.html
- 然后就是利用生成的bjam脚本编译源码了。
volnet @Ubuntu :~/sourcecode/boost_1_42_0$ sudo ./bjam -a -sHAVE_ICU=1 installNote: Building Boost.Regex with Unicode/ICU support enabled Using ICU in /usr/include- ./是unix-like系统执行文件的前缀,这里就是指要执行bjam文件。
- -a是参数,代表重新编译(Rebuild)。输入./bjam -h获得更多帮助。
- -sHAVE_ICU=1,代表支持Unicode/ICU。点击这里(http://goo.gl/ySEe)
前提:系统内需要安装有libicu-dev,可以在终端输入:
sudo apt-get install libicu-dev - install,表示安装
- --clean,表示清理。当前语句中包含-a,则不需要先手动清理,否则需要先运行
./bjam --clean
- 如果你执行上一步,会出现诸如:mpi的问题,多半是本机没有安装mpi。根据系统提示,你可以找到有/home/volnet/sourcecode/boost_1_42_0/tools/build/v2/user-config.jam。在文件最后跟上
using mpi ;即可。然后如果还是有mpi问题,说明本机没有安装mpi。sudo apt-get install mpi-default-dev
界此应该顺利通过编译了。并在/usr/local/lib下有了boost的库了。
下面讨论一下链接静态链接库在Eclipse里的问题。
在 Unix variants 向导里,官方提供了一个使用正则表达式的程序。
在Eclipse里,新增c++ project,并使用Linux C++编译器。将代码拷贝到文件中:
因为要静态链接到正则表达式的库,所以如下图所示,设置对应的*.a文件路径到eclipse,以使链接器能够找到它。
编译通过!
为了我们的程序能够正确载入,我们需要让我们的程序在我们的系统范围内也能够找到我们的库。这时候我们需要在设置一下。详见 这部分 的相关介绍。
测试程序!
volnet
@Ubuntu :~/workspace/boost_get_started/Debug$ ./boost_get_started < test
Will Success Spoil Rock Hunter?
这里test是一个文件。
Will Success Spoil Rock Hunter?