linux下安装boost库环境

来源:互联网 发布:js调用mvc方法 编辑:程序博客网 时间:2024/06/05 10:04
一、在ubuntu下编译一个C++文件
1.新建一个11.cpp   
2.安装g++并编译11.cpp
apt-get install g++ g++ -o  aa  11.cpp
-o 编译生成指定名字的执行文件
3.运行文件
./aa
 
一、什么是boost
Boost是一个功能强大,构造精良、跨越平台、代码开源、完全免费的C++程序库
C++11标准库中2/3来自boost,因此boost是一个C++标准库。
Boost是一个可移植、提供源代码的C++库,作为标准库的后备,是C++标准化进程的开发引擎之一。 BoostC++标准委员会库工作组成员发起,其中有些内容有望成为下一代C++标准库内容。
Boost.Asio是一个跨平台的、主要用于网络和其他一些底层输入/输出编程的C++库。
 
Boost库大部分类库是不需要编译,直接包含头文件即可。
例:要使用shared_ptr,只需在程序中#include<boost/shared_ptr.hpp>
 
二、安装boost
boost中用到了别的函数库,所以为了使用boost中相应的功能,需要先安装系统中可能缺失的库
apt-get install mpi-default-dev  #安装mpi  
apt-get install libicu-dev     #支持正则表达式的UNICODE字符集   
apt-get install python-dev     #需要python的话  
apt-get install libbz2-dev     #如果编译出现错误:bzlib.h: No such file or directory  
如果在安装以上库失败的话可以尝试一下用
sudo apt-get update  
Boost库官网:http://www.boost.org/
boost_1_64_0.tar.gz包地址:
https://dl.bintray.com/boostorg/release/1.64.0/source/boost_1_64_0.tar.gz
解压:tar -zxvf boost_1_64_0.tar.gz
运行 ./bootstrap.sh./b2 install
 
测试程序:
#include <boost/asio/yield.hpp> 
#include <boost/asio/coroutine.hpp> 
#include <iostream> 
boost::asio::coroutine c;
void foo(int i)
{ reenter(c)
{ yield std::cout<<"foo1 "<<i<<std::endl;
  fork foo(100);
yield std::cout<<"foo2 "<< i+1<<std::endl;
}
}
int main() {
 foo(1); foo(2); foo(3);return 0;
}
编译并运行 test.cpp

原创粉丝点击