Linux编译安装boost-1_52

1.下载 boost-1_52  http://sourceforge.net/projects/boost/files/boost/1.52.0/
2. 将文件解压在/usr/local/目录下
3. 进入/usr/local/boost-1_52_0/ 目录, 在terminal中输入
                         ./bootstrap.sh
4.进入/usr/local/boost-1_52_0/ 目录,在terminal中输入
                        sudo ./bjam  --layout=versioned --build-type=complete --toolset=gcc install 
5.添加环境变量(刚改完要重启或者注销一下来更新刚修改过的环境变量)
   两种方法:
   (1)修改/etc/profie文件 末尾添加
            export BOOST_INCLUDE=/usr/local/include/boost-1_52
            export BOOST_LIB=/usr/local/lib
    (2)在/etc/profile.d/ 中新建一个shell文件boost.sh
             #!/bin/sh 
             export BOOST_INCLUDE=/usr/local/include/boost-1_52
             export BOOST_LIB=/usr/local/lib

测试:
test.cpp

#include <boost/lexical_cast.hpp>
#include <iostream>
int main()
{
        using boost::lexical_cast;
        int a = lexical_cast<int>("123");
        double b = lexical_cast<double>("123.12");
        std::cout<<a<<std::endl;
        std::cout<<b<<std::endl;
        return 0;
}

编译:
g++ test.cpp -I$BOOST_INCLUDE -L$BOOST_LIB -o test
./test
输出:
123
123.12        
=================================【转载】============================================
http://www.cppfun.com/2012/03/31/codeblocks-with-boost-under-linux.html
Set up a Code::Blocks global variable for Boost
global variable

global variable

This step only needs to be performed once, after which the global variable you’ve created will be available for any project.

  • Open the Settings menu and select “Global variables…”
  • Click the “New” button next to the Current variable list, specify a name like “boost”, and hit OK
  • In the “base” field of the Builtin fields section, browse for the base of your Boost location — the path you specified in the –prefix option of the build command( * mandatory)
  • In the “include” field, browse for the header files location — the path can same with the “base” or like “/usr/local/include” or /usr/include.
  • In the “lib” field, browse for the “stage/lib” subfolder of your Boost installation — it should be the path in the “base” field with “/stage/lib” tacked on. (This is the folder that contains either multiple lib*.a or *.lib files.)[maybe a path like "/usr/local/lib" or  "/usr/lib"].
  • Hit the Close button to save your global variable
Add Boost search directories to your project
search directories - compiler

search directories - compiler

search directories - linker

search directories - linker

  • Right-click your project’s name in the Projects section of the Management window and select “Build options…”
  • Highlight the root of your project in the tree on the left side of the Project build options window
  • Select the “Search directories” tab
  • With the “Compiler” subtab selected, click the Add button, enter “$(#boost.include)” (without the quotes), and hit OK
  • With the “Linker” subtab selected, click the Add button, enter “$(#boost.lib)” (without the quotes), and hit OK
Include Boost headers and link with Boost libraries

Your project is now ready to use the Boost libraries. For each library you want to use, do the following:

  • #include <boost/*.hpp> in your source file
  • In your project’s build options, highlight the root of your project, select the “Linker settings” tab, and add “boost_*” to your Link libraries[or another way under "Other link options" something like "-lboost_system -lboost_thread -..."]
Add Other libraries into Code::Blocks

The same way like boost, just do as above steps, enjoy.


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值