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
2. 将文件解压在/usr/local/目录下
3. 进入/usr/local/boost-1_52_0/ 目录, 在terminal中输入
4.进入/usr/local/boost-1_52_0/ 目录,在terminal中输入
5.添加环境变量(刚改完要重启或者注销一下来更新刚修改过的环境变量)
测试:
test.cpp
#include <boost/lexical_cast.hpp>
#include <iostream>
int main()
{
}
编译:
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](http://www.cppfun.com/wp-content/uploads/2012/03/global-300x238.png)
global variable
This step only needs to be performed once, after which the
- 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](http://www.cppfun.com/wp-content/uploads/2012/03/compiler-300x268.png)
search directories - compiler
![search directories - linker search directories - linker](http://www.cppfun.com/wp-content/uploads/2012/03/linker-300x269.png)
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.