Ubuntu 安装 boost 库

来源:互联网 发布:linux添加用户的命令 编辑:程序博客网 时间:2024/04/30 06:27

1.  首先从网站 http://www.boost.org/  下载 boost 库

2.1 .安装附加依赖库

[html] view plain copy
  1. sudo apt-get update  
[html] view plain copy
  1. sudo apt-get install build-essential g++ python-dev autotools-dev libicu-dev build-essential libbz2-dev libboost-all-dev  

2.2 运行脚本文件,--prefix参数,可以指定安装路径,如果不带--prefix参数的话(推荐),默认路径是 /usr/local/include 和 /usr/local/lib,分别存放头文件和各种库。执行完成后,会生成bjam,已经存在的脚本将会被自动备份。

[html] view plain copy
  1. ./bootstrap.sh --prefix=/usr/local  


2.3 安装boost,也就是将头文件和生成的库,放到指定的路径(--prefix)下
[html] view plain copy
  1. ./b2 install --prefix=PREFIX   where PREFIX is a directory where you want Boost.Build to be installed.  

2.4 测试是否安装成功 ,建立一个boost_test.cpp 文件 

[cpp] view plain copy
  1. vim boost_test.cpp  


2.5 编辑boost_test.cpp 文件

[html] view plain copy
  1. #include <iostream>  
  2. #include <boost/array.hpp>  
  3.   
  4. using namespace std;  
  5. int main(){  
  6.   boost::array<int, 4> arr = {{1,2,3,4}};  
  7.   cout << "hi" << arr[0]<<endl;  
  8.   return 0;  
  9. }  




[html] view plain copy
  1. #include <iostream>  
  2. #include <boost/array.hpp>  
  3.   
  4. using namespace std;  
  5. int main(){  
  6.   boost::array<int, 4> arr = {{1,2,3,4}};  
  7.   cout << "hi" << arr[0]<<endl;  
  8.   return 0;  
  9. }  
0 0