linux下安装boost与测试

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

去官方网站下载最新的:www.boost.org

一,下载,编译安装,
需要到官方网站下载最新的版本,最新已经到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 <boost/version.hpp>
#include <boost/config.hpp>
#include <boost/lexical_cast.hpp>
#include <iostream>

using namespace std;

int main()
{
  using boost::lexical_cast;
  int a= lexical_cast<int>("123456");
  double b = lexical_cast<double>("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
  • 2
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

北雨南萍

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值