Ubuntu 15.04 安装 boost-python
1. 安裝依賴(lài)庫(kù)
sudo apt-get install python-dev sudo apt-get install mpi-default-dev #安裝mpi庫(kù) sudo apt-get install libicu-dev #支持正則表達(dá)式的UNICODE字符集 sudo apt-get install libbze-dev # 如果編譯出現(xiàn)錯(cuò)誤:bzlib.h : No such file or directory sudo apt-get update
2. 手動(dòng)安裝Boost
2.1 下載 boost源代碼,然后編譯 boost (C++11 Python fPIC),或者訪問(wèn) 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會(huì)生成 b2和bjam文件。可查看使用方法
./bootstrap.sh -help2.2 編譯 boost
sudo ./b2 install ./b2 cxxflags=-fPIC cflags=-fPIC --c++11成功后會(huì)出現(xiàn)
The Boost C++ Libraries were successfully built!2.3 建立一個(gè) test.cpp文件測(cè)試
gedit test.cpp添加如下內(nèi)容
#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執(zhí)行
./test結(jié)果
33. 安裝gflags
3.1 下載 gflags
安裝命令,安裝參數(shù)詳細(xì)介紹見(jiàn)INSTALL.md
3.2 編輯CMakeList
gedit CMakeLists.txt添加 -fPIC選項(xiàng)(在文件靠近開(kāi)頭的地方添加下面一行):
set (CMAKE_POSITION_INDEPENDENT_CODE True)生成Makefile
cmake .檢查是否在CMakeFiles/flags.cmake中成功生成-fPIC
grep -R fPIC ./build/CMakeFiles/出現(xiàn)如下結(jié)果
./build/CMakeFiles/gflags_nothreads_static.dir/flags.make:CXX_FLAGS = -03 -DNDEBUG -fPIC ./build/CMakeFiles/gflags_static.dir/flags.make:CXX_FLAGS = -03 -DNDEBUG -fPIC3.3 編譯 gflags (+ fPIC)
make make test #(optional) sudo make install4. 配置
4.1 在工程的根目錄下創(chuàng)建boost-build.jam,添加下列行
cd boost_1_63_0 gedit bootstrap.jam添加如下內(nèi)容
boost-build /home/bids/boost_1_63_0/tools/build/src其中后面的這個(gè)路徑應(yīng)該為你本機(jī)里包含bootstrap.jam的路徑。
然后在包裝c++函數(shù)給python的源碼文件目錄中添加Jamroot文件。
4.2 編輯 jamroot
gedit jamroot添加如下示例如下(詳見(jiàn)中文注釋)
# 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. # 注:此目錄應(yīng)該指向工程自己的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. # 注:下面示例動(dòng)態(tài)庫(kù)so工程,文件路徑應(yīng)該指向你自己的這兩個(gè).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. # 注:此處應(yīng)包含所有生成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 ;參考文獻(xiàn)
在Ubuntu上安裝boost庫(kù)
Ubuntu 14.04 安裝boost-python并配置工程指南
總結(jié)
以上是生活随笔為你收集整理的Ubuntu 15.04 安装 boost-python的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 为谁而炼金新手攻略 初始选择及强力角色推
- 下一篇: python 常见问题汇总(待续)