1. 安装依赖库


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

2. 手动安装Boost


2.1 下载 boost源代码,然后编译 boost (C++11 Python fPIC),或者访问 boost.org.

#解压
unzip boost_1_63_0.zip
cd boost_1_63_0
./bootstrap.sh --with-python=PYTHON
./bootstrap.sh --with-libraries=system,thread,python

会生成 b2和bjam文件。可查看使用方法

./bootstrap.sh -help

2.2 编译 boost

sudo ./b2 install
./b2 cxxflags=-fPIC cflags=-fPIC --c++11

成功后会出现

The Boost C++ Libraries were successfully built!

2.3 建立一个 test.cpp文件测试

gedit 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;}

编译

g++ test.cpp -o test

执行

./test

结果

3

3. 安装gflags


3.1 下载 gflags


安装命令,安装参数详细介绍见INSTALL.md


3.2 编辑CMakeList

gedit CMakeLists.txt

添加 -fPIC选项(在文件靠近开头的地方添加下面一行):

set (CMAKE_POSITION_INDEPENDENT_CODE True) 

生成Makefile

cmake .

检查是否在CMakeFiles/flags.cmake中成功生成-fPIC

grep -R fPIC ./build/CMakeFiles/  

出现如下结果

./build/CMakeFiles/gflags_nothreads_static.dir/flags.make:CXX_FLAGS = -03 -DNDEBUG -fPIC
./build/CMakeFiles/gflags_static.dir/flags.make:CXX_FLAGS = -03 -DNDEBUG -fPIC

3.3 编译 gflags (+ fPIC)

make
make test   #(optional)
sudo make install

4. 配置


4.1 在工程的根目录下创建boost-build.jam,添加下列行

cd boost_1_63_0
gedit bootstrap.jam

添加如下内容

boost-build /home/bids/boost_1_63_0/tools/build/src

其中后面的这个路径应该为你本机里包含bootstrap.jam的路径。


然后在包装c++函数给python的源码文件目录中添加Jamroot文件。


4.2 编辑 jamroot

gedit jamroot

添加如下示例如下(详见中文注释)

# Copyright David Abrahams 2006. Distributed under the Boost
# Software License, Version 1.0. (See accompanying
# file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)  import python ;  if ! [ python.configured ]
{   ECHO "notice: no Python configured in user-config.jam" ;   ECHO "notice: will use default configuration" ;  using python ;
}  # Specify the path to the Boost project.  If you move this project,
# adjust this path to refer to the Boost root directory.  # 注:此目录应该指向工程自己的boost-build.jam所在目录
use-project boost  : /home/bids/boost_1_63_0/tools/build/src ;  # Set up the project-wide requirements that everything uses the
# boost_python library from the project whose global ID is
# /boost/python.
# 注:下面示例动态库so工程,文件路径应该指向你自己的这两个.a文件的安装路径
project  : requirements <link>shared  <library-file>/usr/local/lib/libboost_python.a  <library-file>/usr/local/lib/libgflags.a  ;  # Declare the three extension modules.  You can specify multiple
# source files after the colon separated by spaces.
# 注:此处应包含所有生成so所需要编译的源代码文件
python-extension word_net : wordnet_python_wrapper.cc wordnet_tool.cc word_tool.cc utils.cc ;  # Put the extension and Boost.Python DLL in the current directory, so
# that running script by hand works.
install convenient_copy   : word_net   : <install-dependencies>on <install-type>SHARED_LIB <install-type>PYTHON_EXTENSION   <location>.   ;  # A little "rule" (function) to clean up the syntax of declaring tests
# of these extension modules.
local rule run-test ( test-name : sources + )
{  import testing ;  testing.make-test run-pyd : $(sources) : : $(test-name) ;
}  # Declare test targets
# 注:建议添加test脚本配置
run-test wordnet : word_net wordnet_python_test.py ;  


参考文献


在Ubuntu上安装boost库

Ubuntu 14.04 安装boost-python并配置工程指南

Ubuntu 15.04 安装 boost-python相关推荐

  1. Ubuntu 15.04 安装TensorFlow(源码编译) 及测试梵高作画

    介绍Google的TensorFlow机器学习开源库,在UbuntuKylin上的安装和和源码编译. 原始官方文档参见:http://www.tensorflow.org. 本电脑配置如下: 3.19 ...

  2. Ubuntu 15.04 安装 Nvidia Quadro系列显卡驱动

    在这之前,我用的Ubuntu都是系统自带的驱动, 由于分辨率没有任何问题, 所以一直没有安装Nvidia官方的驱动; 近期更新到 15.04 之后, 在播放avi 格式的常规视频时却出现闪烁的现象, ...

  3. ubuntu 15.04安装VMware11

    原文:http://www.linuxidc.com/Linux/2015-01/111791.htm 1.下载安装包 wget https://download3.vmware.com/softwa ...

  4. u盘如何安装xp和linux双系统,U盘安装Windows和Ubuntu 15.04双系统图解教程

    本文为Ubuntu 15.04安装参考文章,方法是一样的,可做为安装Ubuntu的总体教程,亲测能安装成功. 采用在线升级到Ubuntu 15.04的方法: 从Ubuntu 14.04/Ubuntu ...

  5. django本地安装mysql_Ununtu 15.04 安装MySql(Django连接Mysql)

    本文介绍Ubuntu 15.04下安装MySQL ubuntu 15.04安装mysql django项目连接mysql 一.安装数据库 1.sudo apt-get install mysql-se ...

  6. Caffe + Ubuntu 15.04/16.04 + CUDA 7.5/8.0 在服务器上安装配置及卸载重新安装(已测试可执行)

    本文参考如下: caffe 安装所需的所有资源可在百度网盘下载 链接: http://pan.baidu.com/s/1jIRJ6mU 提取密码:xehi 在服务器上为每个子用户拷贝caffe 使用 ...

  7. 安装完Ubuntu 15.04桌面后要做的15件事

    2019独角兽企业重金招聘Python工程师标准>>> 本教程适用于在自己的电脑上安装了Ubuntu 15.04 "Vivid Vervet" 桌面的新手,这里会 ...

  8. linux notepad 安装教程,Ubuntu 15.04/14.10/14.04下安装和卸载Notepad++(notepadqq)

    Ubuntu下的Notepad++也就是notepadqq,比较适合刚从Windows平台转移到Linux平台的用户使用,如果你一直在Windows下使用的是nodepad++,那么推荐你在Linux ...

  9. VMWare 15中Ubuntu 18.04安装VMWare Tools

    VMWare 15中Ubuntu 18.04安装VMWare Tools 这篇文章写给以后的自己看,因为怕以后忘了. 1.先点击"虚拟机"之后点击"安装VMWare To ...

最新文章

  1. 16. Logging 模块的配置与使用
  2. MOCTF-Web-一道水题
  3. js的字符串和变量拼接
  4. bash给脚本加进度条_shell脚本实现多彩进度条
  5. 传感器市场需求大幅提升 中企能否满足?
  6. fw313r虚拟服务器,迅捷FW313R无线wifi怎么设置上网 - falogincn登录页面
  7. DDS核心规范-DDS v1.4、DDSI-RTPS、IDL
  8. 火狐无法安装扩展_立即安装4个Firefox扩展
  9. 【开源】EasyDarwin编译全过程:Linux系统下编译运行最新版EasyDarwin的步骤介绍
  10. GitHub 加速神器, 来了!
  11. Windows 7 频繁提示:计算机的内存不足
  12. android神器,android神器:tasker
  13. win10 的局部截图功能
  14. 【案例练习】14—23个Javascript实现的倒数计时器案例
  15. 学计算机会设置路由器,Win7电脑怎么设置无线路由器上网
  16. UCOSIII从官网(2021)下载
  17. scon——构建管理器
  18. 多媒体视频开发_(6) EasyDarwin开源流媒体服务器程序搭建
  19. base64 string 放不下_用 Base64 编码插入 Markdown 图片
  20. win10电脑右键新建没有记事本的解决方法

热门文章

  1. c语言二叉树的生成,C语言实现二叉树的创建以及遍历(递归)
  2. 算法训练 最小乘积(基本型) (蓝桥杯水题)
  3. 安装Python3的工具包报Microsoft Visual C++ 14.0 is required的错误
  4. linux 后台计算,科学网-如何在Linux中做批处理和后台计算-张彦的博文
  5. 回溯法解整数的划分问题(C语言)
  6. 【论文阅读】A Gentle Introduction to Graph Neural Networks [图神经网络入门](4)
  7. 计算机体系结构-- 第一章4--计算机体系结构
  8. 【算法竞赛学习】二手车交易价格预测-Task3特征工程
  9. 用Eclipse开发项目,你不能不知道的快捷键
  10. codeforce 227D Naughty Stone Piles (贪心+递归+递推)