Ubuntu 15.04 安装 boost-python(python3) 目的为了安装denseinferencewrapper

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-bin-path]
./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

 

You can very easily port this to pytho-3, all you need to run boost with the correct python_verdsion flags. Following are the steps to do it:

Install python 3.5 :

sudo apt-get install python3-dev

Make sure you have the libboost-python-dev libraries installed:

sudo apt-get install libboost-python-dev

Download the lastest version of Boost from http://www.boost.org/
Run bootstrap with correct flags :

./bootstrap.sh --with-python=python3.5

Compile Boost in directory :

./b2

Update the Makefile to take the new boost locations(sharing my makefile)

CC	= g++
CFLAGS	= -W -Wall -O2 -DNDEBUG
#CFLAGS	= -W -Wall -g
LIB_ROOT = denseinference/lib/

all: 
	make -C clean
	make -C python

clean:
	rm -f *.a
	rm -f *.o
	rm -f *.so

libDenseCRF.a: libDenseCRF/bipartitedensecrf.cpp libDenseCRF/densecrf.cpp libDenseCRF/filter.cpp libDenseCRF/permutohedral.cpp libDenseCRF/util.cpp libDenseCRF/densecrf.h libDenseCRF/fastmath.h libDenseCRF/permutohedral.h libDenseCRF/sse_defs.h libDenseCRF/util.h
	$(CC) -fPIC libDenseCRF/bipartitedensecrf.cpp libDenseCRF/densecrf.cpp libDenseCRF/filter.cpp libDenseCRF/permutohedral.cpp libDenseCRF/util.cpp -c $(CFLAGS) -DNDEBUG
	ar rcs libDenseCRF.a bipartitedensecrf.o densecrf.o filter.o permutohedral.o util.o
	
dense_inference.so: dense_inference.o libDenseCRF.a
	$(CC) -shared -I/usr/include/python3.5m -Wl,-no-undefined -o dense_inference.so dense_inference.o -lboost_python-py35 -lpython3.5m -L. -lDenseCRF $(CFLAGS)
	
dense_inference.o: refine_3d/dense_inference.cpp refine_3d/dense_inference.h libDenseCRF.a
	$(CC) -c -fPIC -I/usr/include/python3.5m refine_3d/dense_inference.cpp -o dense_inference.o $(CFLAGS) -lDenseCRF $(CFLAGS)
	
python: dense_inference.o dense_inference.so libDenseCRF.a

.PHONY: default clean
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值