boost 库学习——Ubuntu 安装boost 库

环境:ubuntu 14.04

安装方法一:apt-get

sudo apt-get install libboost-dev

安装方法二:编译安装

安装依赖库

sudo apt-get install mpi-default-dev  #安装mpi库  
sudo apt-get install libicu-dev     #支持正则表达式的UNICODE字符集   
sudo apt-get install python-dev     #需要python的话  
sudo apt-get install libbz2-dev     #如果编译出现错误:bzlib.h: No such file or directory

注意,复制粘贴的时候,不要复制命令后面的空格,这样会导致一个无法定位软件包的错误

下载boost:下载地址

解压:

tar -zxf boost_1_69_0.tar.gz

进入解压目录,执行:

./bootstrap.sh
sudo ./b2
sudo ./b2 install

简单使用

代码路径:

./
├── makefile
└── test.cpp

test.cpp

#include<iostream>
#include<boost/bind.hpp>
using namespace std;
using namespace boost;
int fun(int x,int y){return x+y;}
int main(){
    int m=1;int n=2;
    cout<<boost::bind(fun,_1,_2)(m,n)<<endl;
    return 0;
}

Makefile:

target=test                          

#inc=-I/usr/local/include/boost/
#lib=-L/usr/local/lib

$(target): test.cpp
    g++ -ggdb3 -o $@ $^ $(inc) $(lib)

clean:
    rm -rf $(target) *.o

其中注释掉的是默认的安装路径,不加上也可以的~

参考:

Boost C++ 库 中文文档

ubuntu下安装boost

Ubuntu上完全编译安装boost

猜你喜欢

转载自blog.csdn.net/guangyacyb/article/details/85309627