boost安装⽬录linux,Linux编译和安oost库(⽰例代码)1. 下载boost安装包并解压缩
下载完成后进⾏解压缩:
tar zxvf boost_1_58_
1
2.设置编译器和所选库
先进⼊解压缩后的⽬录:
cd boost_1_58_0
1
然后运⾏bootstrap.sh脚本并设置相关参数:
./bootstrap.sh --with-libraries=all --with-toolset=gcc
1
-
-with-libraries指定编译哪些boost库,all的话就是全部编译,只想编译部分库的话就把库的名称写上,之间⽤ , 号分隔即可,可指定的库有以下⼏种:
库名说明
atomic
chrono
context
coroutine
date_time
exception
filesystem
graph图组件和算法
graph_parallel
iostreams
locale
log
math
mpi⽤模板实现的元编程框架
program_options
python把C++类和函数映射到Python之中
random
regex正则表达式库
serialization
signals
system
test
thread可移植的C++多线程库
timer
wave
--with-toolset指定编译时使⽤哪种编译器,Linux下使⽤gcc即可,如果系统中安装了多个版本的gcc,在这⾥可以指定gcc的版本,⽐如--with-toolset=gcc-4.4
命令执⾏完成后看到显⽰如下即为成功:
Building Boost.Build engine with tools/build/src/engine/bin.linuxx86_64/b2
Detecting 2.6
Detecting /usr
Unicode/ICU support for Boost.Regex?... not found.
Generating Boost.Build configuration in
Bootstrapping is done. To build, run:
./b2
To adjust configuration, edit ‘project-config.jam‘.
Further information:
- Command line help:
./b2 --help
- Getting started guide:
- Boost.Build documentation:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
3.编译boost
执⾏以下命令开始进⾏boost的编译:
./b2 toolset=gcc
1
编译的时间⼤概要10多分钟,耐⼼等待,结束后会有以下提⽰:
...failed updating
...skipped
...updated
1
2
3
4.安oost
最后执⾏以下命令开始安oost:
./b2 install --prefix=/usr
1
--prefix=/usr⽤来指定boost的安装⽬录,不加此参数的话默认的头⽂件在/usr/local/include/boost⽬录下,库⽂件在/usr/local/lib/⽬录下。这⾥把安装⽬录指定为--prefix=/usr则boost会直接安装到系统头⽂件⽬录和库⽂件⽬录下,可以省略配置环境变量。
安装完毕后会有以下提⽰:
...failed updating
...skipped
...updated
1
2
3
最后需要注意,如果安装后想马上使⽤boost库进⾏编译,还需要执⾏⼀下这个命令:
ldconfig
1
更新⼀下系统的动态链接库
5.boost使⽤测试
以boost_thread为例,测试刚安装完的boost库是否能正确使⽤,测试代码如下:#include //包含boost头⽂件
#include
#include
using namespace std;
volatile bool isRuning = true;
void func1()
{
static int cnt1 = 0;
while(isRuning)
{
cout << "func1:" << cnt1++ << endl;
sleep(1);
}
}
void func2()
{
static int cnt2 = 0;
while(isRuning)
{
cout << "func2:" << cnt2++ << endl;
sleep(2);
}
}
int main()
{
boost::thread thread1(&func1);
boost::thread thread2(&func2);
system("read");
isRuning = false;
thread2.join();
thread1.join();
cout << "exit" << endl; return 0;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
python默认安装路径
28
29

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。