【问题标题】:Exposing C++ to Python error from BoostPython将 C++ 暴露给来自 BoostPython 的 Python 错误
【发布时间】:2014-04-18 14:08:07
【问题描述】:

我正在通过 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。

关于在哪里找到丢失的符号有什么建议吗?

【问题讨论】:

  • try include #include &lt;boost/python/module.hpp&gt; 你需要这个 include 来定义模块。
  • 不行。它仍然缺少符号。我注意到 libboost_python.a 和 libboost_python.so 中的符号都未定义
  • 这看起来很有希望......我没有 python3 boost 库。我要重新编译 boost 确保 boost 与我的 python 安装一致。

标签: python c++ boost


【解决方案1】:

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

【讨论】:

    【解决方案2】:

    _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 的问题

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-09-19
      • 2012-12-21
      • 1970-01-01
      相关资源
      最近更新 更多