Ubuntu 15.04 安装 boost-python
生活随笔
收集整理的這篇文章主要介紹了
Ubuntu 15.04 安装 boost-python
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
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 -help2.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結果
33. 安裝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 -fPIC3.3 編譯 gflags (+ fPIC)
make make test #(optional) sudo make install4. 配置
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的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 为谁而炼金新手攻略 初始选择及强力角色推
- 下一篇: 京门风月手游烹饪全甲攻略 全部菜品做法详