• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
MKT-porter
博客园    首页    新随笔    联系   管理    订阅  订阅
camke(3)配置boost

 

 

安装教程

 

https://blog.csdn.net/yhrun/article/details/8099630

直接安装
sudo apt-get install libboost-dev

从源码安装
下载 https://www.boost.org/ 压缩包 解压
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

#编译 默认路径是 /usr/local/include 和 /usr/local/lib,分别存放头文件和各种库
sudo ./bootstrap.sh
#安装
sudo ./b2 install

 

 

工程引用

 

 

 

 

CMakeLists.txt

# cmake needs this line
cmake_minimum_required(VERSION 3.1)

# Define project name
project(boost_example_project)



find_package(Boost COMPONENTS regex system REQUIRED)


include_directories(${Boost_INCLUDE_DIRS})

MESSAGE( STATUS "Boost_INCLUDE_DIRS = ${Boost_INCLUDE_DIRS}.")
MESSAGE( STATUS "Boost_LIBRARIES = ${Boost_LIBRARIES}.")
MESSAGE( STATUS "Boost_LIB_VERSION = ${Boost_LIB_VERSION}.")

add_executable(boost_example example.cpp)
target_link_libraries (boost_example ${Boost_LIBRARIES})

  

example.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;
}

 

使用编译

 

mkdir build
cd build
cmake ..
make
./boost_example

 

 

  

 

 

 

 

  

 

posted on 2021-05-31 16:14  MKT-porter  阅读(74)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3