http://www.cppblog.com/wfcadd/archive/2011/04/06/143513.html
http://www.cppblog.com/mymsdn/archive/2010/03/30/install-boost-under-boost.html
1.从boost官网下载boost 1.46.1 2.执行 apt-get install build-essential (目的是为了安装好象gcc,g++等一些工具进行编译) 注:我是在root用户下进行的操作,普通用户执行 sudo apt-get install build-essential 3.解压boost库到/usr/share/ 將下载好的boost 1.46.1.tar.gz(我用的是这个版本) 复制到/usr/share/ 目录下,然后解压,会自动生成一个boost_1_46_1这个文件夹(或者用命令解压,这里就不提了,可以自己去查解压命令) 4.编译bjam(这个东东是用来编译boost库的) 编译之前先做如下操作,由于这版本是编译msvc版的bjam,我们把它改成gcc版的bjam...... 进入boost1.46.1解压目录找到bootstrap.bat 用记事本打开,然后修改: 第13行將call ./build.bat > ../../../bjam.log 改为call ./build.bat gcc > ../../../bjam.log 第33行將set toolset=msvc改为set toolset=gcc 保存退出,然后双击 bootstrap.sh在终端中执行,稍等片刻会在boost_1_46_1中生成bjam 5.编译boost库: 在终端中进入/usr/share/boost_1_46_1目录 在终端中输入 cd /usr/share/boost_1_46_1 然后我在root用户下输入 ./bjam toolset=gcc --layout=tagged --build-type=complete stage 进行完全编译 (普通用户的话执行: sudo ./bjam toolset=gcc --layout=tagged --build-type=complete stage ) 经过漫长的等 待,命令执行完毕后,将会生成所有版本的库,并存储在: /usr/share/boost_1_46_1/stage 下 6.boost 已经编译好了,下面调用boost库 1.在/usr/include/下生成一个boost库的include文件夹连接: ln -s /usr/share/boos t_1_46_1/boost /usr/include/boost 2.在/usr/lib/ 下生成所有boost编译出的lib库文件的对应连接 切换到stage目录下,执行 find $PWD/lib/*.* -type f -exec ln -s {} /usr/lib/ /; (普通用户执行: sudo find $PWD/lib/*.* -type f -exec ln -s {} /usr/lib/ /; ) 执行完以上操作就算ok了
这不是一篇向导,全面的向导请看这里 (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是一个文件。