source : http://blog.sina.com.cn/s/blog_610c4a3601018did.html
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中输入
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
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 *.libfiles.)[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 - 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.