[英]Exposing C++ to Python error from BoostPython
我正在通過 BoostPython 庫向 Python 公開一個簡單的 C++ 代碼:
#include <boost/python/detail/wrap_python.hpp>
#include <boost/python.hpp>
using namespace boost::python;
bool test_api( void ){
return true;
};
BOOST_PYTHON_MODULE(materials) {
def( "test_api", test_api );
}
在我嘗試導入此模塊后,python 解釋器返回錯誤:
ImportError: ./example.so: undefined symbol: _Py_RefTotal
我已經將模塊靜態鏈接到 boost python 庫,並且工作目錄中存在 python 動態庫 libpython3.2m.so 和 libpython3.2m.so.1.0。
關於在哪里找到丟失的符號的任何建議?
Boost庫與Python安裝不一致。
cd boost_source
./bootstrap.sh --with-libraries=python --prefix=../boost_target
要配置Boost指向正確的Python安裝:
vim tools/build/v2/user-config.jam
編輯指向Python的行:
using python : version_number
: path_to_python_executable
: path_to_python_include_directory
: path_to_python_library_directory
然后,運行構建系統:
./b2
_Py_RefTotal 在 object.h 中定義在預編譯器保護下:
$less include/python3.6m/object.h
#ifdef Py_REF_DEBUG
PyAPI_DATA(Py_ssize_t) _Py_RefTotal;
...
...
#endif /* Py_REF_DEBUG */
我正在鏈接python3.6m
但包括來自include/python3.6dm
頭文件。 修復了包括 ptyhon3.6m 在內的問題
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.