Chinaunix首页 | 论坛 | 博客
  • 博客访问: 7790836
  • 博文数量: 701
  • 博客积分: 2150
  • 博客等级: 上尉
  • 技术积分: 13233
  • 用 户 组: 普通用户
  • 注册时间: 2011-06-29 16:28
个人简介

天行健,君子以自强不息!

文章分类

全部博文(701)

文章存档

2019年(2)

2018年(12)

2017年(76)

2016年(120)

2015年(178)

2014年(129)

2013年(123)

2012年(61)

分类: C/C++

2016-04-09 08:33:03

Boost库是一个功能强大,构造精巧,跨平台,开源并且完全免费的C++程序库,
它作为标准库的后备,是C++标准化进程的发动机之一,
在linux安装过程如下:

去官方网站下载最新的:

一,下载,编译安装,
需要到官方网站下载最新的版本,最新已经到1.60.0。
$ tar -jxvf boost_1_60_0.tar.bz2 
$ cd boost_1_60_0/
$ sudo ./bootstrap.sh 

1. 只编译不安装使用下面的命令
$ ./b2
...
...updated 1134 targets...
The Boost C++ Libraries were successfully built!

The following directory should be added to compiler include paths:
    /opt/cpp_practice/boost/boost_1_60_0

The following directory should be added to linker library paths:
    /opt/cpp_practice/boost/boost_1_60_0/stage/lib

2. 编译并安装则用下面的命令:
$ ./b2 install
如果像上面这样不指定额外选项,boost将编译release版本的库文件,
把头文件安装到 /usr/local/include,库文件安装到 /usr/local/lib。

3. 也可以完整编译并安装
$ ./b2 --buildtype=complete install
这样会对boost进行完整编译,安装所有调试版,发行版的静态库和动态库。

4. 定制化的编译和安装
执行命令:
$ ./b2 --show-libraries
可查看所有必须编译才能使用的库
在完全编译命令的基础上,使用--with或 --without选择可打开或关闭某个库的编译,
如:
$ ./b2 --with-date_time --buildtype=complete install
则将仅编译和安装date_time库

二,验证开发环境
1. 测试代码
$ cat test_boost.cpp
#include
#include
#include
#include

using namespace std;

int main()
{
  using boost::lexical_cast;
  int a= lexical_cast("123456");
  double b = lexical_cast("123.456");
  std::cout << a << std::endl;
  std::cout << b << std::endl;
  return 0;
}

2.编译,运行
$ g++ -Wall -o test_boost test_boost.cpp
$ ls
test_boost  test_boost.cpp

$ ./test_boost 
123456
123.456
阅读(1860) | 评论(0) | 转发(1) |
给主人留下些什么吧!~~