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