http://my.oschina.net/myspaceNUAA/blog/62219
1. 下载boost库,到官网上下即可。http://www.boost.org/
下载完解压即可
2. 权限设置:
我在安装的过程中出现了如下问题:权限不够
1 | administrator@ubuntu:~/source/boost_1_49_0$ ./bootstrap.sh |
2 | bash: ./bootstrap.sh: Permission denied |
给予其权限:
1 | chmod +x ./bootstrap.sh |
在运行的过程中,又出现权限不足的问题,继续给予权限
1 | administrator@ubuntu:~/source/boost_1_49_0$ ./bootstrap.sh |
2 | ./bootstrap.sh: 1: ./bootstrap.sh: ./tools/build/v2/engine/build.sh: Permission denied |
1 | administrator@ubuntu:~/source/boost_1_49_0/tools/build/v2/engine$ chmod +x ./build.sh |
chmod777*-R
全部子目录及文件权限改为777
3. 编译生成boost的编译引擎 有了足够的权限后,就可以运行bootstrap.sh:编译生成boost的编译引擎
01 | <span style="color:#e53333;">administrator@ubuntu:~/source/boost_1_49_0$ ./bootstrap.sh</span> |
02 | Building Boost.Build engine with toolset gcc... tools/build/v2/engine/bin.linuxx86/b2 |
03 | Detecting Python version... 2.7 |
04 | Detecting Python root... /usr |
05 | Unicode/ICU support for Boost.Regex?... not found. |
06 | Generating Boost.Build configuration in project-config.jam... |
07 |
08 | Bootstrapping is done. To build, run: |
09 |
10 | ./b2 |
11 | |
12 | To adjust configuration, edit 'project-config.jam'. |
13 | Further information: |
14 |
15 | - Command line help: |
16 | ./b2 --help |
17 | |
18 | - Getting started guide: |
19 | http://www.boost.org/more/getting_started/unix-variants.html |
20 | |
21 | - Boost.Build documentation: |
22 | http://www.boost.org/boost-build2/doc/html/index.html |
其编译了boost的编译引擎(bjam/b2)。
4. 开始编译boost程序
1 | administrator@ubuntu:~/source/boost_1_49_0$ ./bjam --prefix==./prefix/install |
2 | Building the Boost C++ Libraries. |
5. 安装boost
1 | administrator@ubuntu:~/source/boost_1_49_0$ ./b2 install |
在安装的时候,即拷贝BOOST生成的文件,又出现了许多权限问题,见控制台输出:
1 | ...failed common.copy /usr/local/lib/libboost_thread.a... |
2 | common.copy /usr/local/lib/libboost_timer.a |
3 | cp: cannot create regular file `/usr/local/lib/libboost_timer.a': <span style="color:#e53333;">Permission denied</span> |
所以就输入了如下命令:
1 | administrator@ubuntu:~/source/boost_1_49_0$ sudo ./b2 install |
增加了权限后,文件确实拷贝成功,放于usr/local/....目录下,但是使用的时候还是说没有权限使用boost,所以直接将普通用户设置为root权限
1 | administrator@ubuntu:~$ sudo vi /etc/passwd |
2 | administrator:<span style="color:#e53333;">x:0:0:</span>Administrator,,,:/home/administrator:/bin/bash |
注销重新登录后,
1 | root@ubuntu:~/source/ThreadPool# g++ -c Thread.cpp -o Thread |
Thread类中可是使用到了boost中的文件的哈
1 | #include <pthread.h> |
2 | #include <string> |
3 | #include <boost/function.hpp> |
4 | #include <boost/bind.hpp> |
获取boost库
Linux下官方提供了两个压缩版本:
boost_1_43_0.tar.bz2
boost_1_43_0.tar.gz
windows平台有:
boost_1_43_0.7z
boost_1_43_0.zip
找到其中一个Unix/Linux包的直接下载地址,然后输入下列命令
sudo wget http://downloads.sourceforge.net/project/boost/boost/1.43.0/boost_1_43_0.tar.gz?use_mirror=cdnetworks-kr-1
解压
tar -zxvf boost_1.43.0.tar.gz
进入解压目录
cd boost_1_43_0
编译安装
使用下面的命令创建boost自己的编译工具bjam(目的是保证Boost在任何平台上都能用bjam编译),类似于GNU Make。
./bootstrap.sh
建议先查看下帮助文档,了解些默认选项,命令为
./bjam –help
常用选项(Options)和属性(Properties)的说明,一般带有–前缀的关键词为option,没有的则为property。
–show-libraries
显示需要编译才能使用的库列表
–build-type=minimal|complete
–build-type=minimal为默认值,此时在Linux下只编译生成release版的动态链接C运行库(C++标准库)的多线程静态库和动态库。
–build-type=complete,在Unix/linux下要编译多个变体(debug或release,多线程或单线程,静态库或动态库,静态链接或动态链接C运行库/C++标准库)。不建议全部编译,费时还费空间,提倡按需编译。
–layout=versioned|tagged|system
决定需要编译的库名及头文件的地址目录名的生成策略。默认Windows下–layout=versioned,Linux下–layout=system。
当同时编译多个版本时,最好设置–layout=versioned或–layout=tagged,否则编译多半会失败,原因是有的版本同时编译若不指定命名策略,可能在输出到指定目录的时候造成命名冲突。
注:–build-type=complete时,不需要设置此属性。但指定variant=debug,release等属性时,须确保–layout=versioned或–layout=tagged。
–build-dir=DIR
指定存放编译过程中生成的中间文件,目标文件等其他文件的目录,默认在./bin.v2。
–with-
创建和安装指定的库
–without-
不对指定的库进行创建和安装,默认创建所有的库
安装:关键词 install 或 stage
./bjam install
install会安装头文件和库文件到相应指定目录,头文件安装到/usr/local/include下,库文件安装到/usr/local/lib下。具体指定安装目录见./bjam –help。
./bjam stage
stage说起来只能说是收集生成的库文件到一个目录下,通常默认就在./stage下。
注:
install 和 stage 貌似不能同时使用,中间会卡住。
若编译过程中未指定install或stage,则生成的目标库文件只存在于–build-dir所指的目录中,默认为./bin.v2。考虑到此,若无需将头文件和库文件安装,则推荐使用stage关键字。
下面是属性:
toolset=toolset
指定编译器,默认自动检测,安装了多个编译器的时候可以使用此属性。
variant=debug|release
指定编译debug或release版本。
link=static|shared
指定创建静态库或动态库
runtime-link=static|shared
指定创建的库是静态链接还是动态链接到C运行库(或C++标准库),这个选项需依据–link的类型,不同的编译器允许的链接策略不一样,比如在GCC下,在生成动态库(–link=shared)时,就不允许进行静态链接到C运行库(或C++标准库)。
threading=single|multi
指定创建多线程或单线程的版本库。
属性可同时设置,如下两种方式,为了避免名字冲突,建议采取propery=value的格式:
./bjam variant=debug,release stage
或
./bjam variant=debug variant=release
这两种方式都可以。
最后执行的创建命令:
sudo ./bjam –without-python –layout=tagged variant=debug,release link=static,shared runtime-link=shared threading=multi stage
本文详细介绍了Boost库在Ubuntu系统下的安装步骤与配置方法,包括解决权限问题、编译生成编译引擎、编译Boost程序及安装过程中的注意事项。

4938

被折叠的 条评论
为什么被折叠?



