Boost Python學習筆記(一)

2022-07-31 00:39:11 字數 1490 閱讀 4025

boost_1_66_0.tar.gz

生成編譯工具

# tar axf boost_1_66_0.tar.gz

# cd boost_1_66_0

# yum install gcc gcc-c++ python-devel cmake -y

# ./bootstrap.sh

編譯32位boost庫

# ./b2 install --with-system --with-thread --with-date_time --with-regex --with-serialization --with-python link=shared runtime-link=shared threading=multi debug
設定boost動態庫載入路徑

# tee /etc/ld.so.conf.d/boost-x86_64.conf << eof

/usr/local/lib

eof# ldconfig

專案初始目錄結構樣例

[root@fcloud example]# tree .

.├── build

├── cmakelists.txt

├── include

│ └── header.h

├── main.cpp

└── src

└── header.cpp

3 directories, 4 files

cmake樣例(編譯後將生成兩個檔案,乙個可執行檔案core,乙個動態庫boost.so)

cmake_minimum_required(version 2.8)

project(boost)

set(cmake_cxx_flags "-wall -g")

### 此處的動態庫名必須和boost_python_module()中定義的保持一致,即最後生成的庫必須名為boost.so

file(glob src "src/*.cpp")

add_library(boost shared $)

add_executable(core main.cpp)

set_target_properties(boost properties prefix "")

#dependencies

include(findpkgconfig)

pkg_check_modules(python required python)

include_directories(include /usr/local/include $)

link_directories(/usr/local/lib $)

target_link_libraries(boost boost_python)

target_link_libraries(core boost $)

Boost Python學習筆記(二)

首先定義乙個動物類 include animal.h pragma once include class animal 其實現 如下 src animal.cpp include include animal.h animal animal std string name name name ani...

Boost Python學習筆記(三)

繼續使用前面的專案,但是先修改下python指令碼 zoo.py 新增add和str函式,分別針對整數 浮點數和字串引數的測試 def add x,y print x y def str s print output s if name main pass然後修改下main.cpp原始檔 using...

Boost python 程式設計記錄

一 使用boost python 使用的是windows,anaconda python2.7 include的路徑包含 anaconda anaconda include,boost include lib的路徑包含 anaconda anaconda libs,boost libs lib有 b...