【问题标题】:Boost Python import fails, symbol of wrapped class not definedBoost Python导入失败,未定义包装类的符号
【发布时间】:2019-08-17 10:06:49
【问题描述】:

我在当前项目中使用 boost python 时遇到问题。当我尝试在 python 3.6 中导入生成的模块时,显示以下错误: ImportError: PythonTrackWrapper.so: undefined symbol: _ZN18PythonTrackWrapperD1Ev 其中 PythonTrackWrapper 是我要包装以在 Python 中使用的类。我无法追踪错误,希望您能提供帮助!

PythonTrackWrapper.cpp:

#include <Python.h>
#include <boost/python.hpp>
#include <boost/tuple/tuple.hpp>

using namespace boost::python;

PythonTrackWrapper::PythonTrackWrapper(std::vector<boost::tuple<double, double>>& left, std::vector<boost::tuple<double, double>>& right, boost::tuple<double, double>& currentPose){

    std::vector<double> X, Y;

    produceTrack(left, right, currentPose, X, Y);

    track = Track(X, Y);

}

BOOST_PYTHON_MODULE(PythonTrackWrapper)
{

    class_<PythonTrackWrapper>("PythonTrackWrapper", init<std::vector<boost::tuple<double, double>>&, std::vector<boost::tuple<double, double>>&, boost::tuple<double, double>&>())
            .def("get_progress_on_track", &PythonTrackWrapper::getProgressOntrack);
}

CMakeLists.txt

cmake_minimum_required(VERSION 3.5)
project(Spline)

set(CMAKE_CXX_STANDARD 17)
find_package(Boost COMPONENTS python3 REQUIRED)

find_package(Python3 3.6 REQUIRED)

...

add_library(PythonTrackWrapper SHARED PythonTrackWrapper.cpp)
set_target_properties(PythonTrackWrapper PROPERTIES SUFFIX .so)
set_target_properties(PythonTrackWrapper PROPERTIES PREFIX "")

target_link_libraries(PythonTrackWrapper Spline boost_python3 ${Boost_LIBRARIES} ${Python3_LIBRARIES})

这是我认为最有可能包含与问题有关的错误的代码,如果您认为原因可能在其他地方,我很乐意发布其余部分。

非常感谢!

【问题讨论】:

  • 如果您想增加有人帮助您的机会,请提供MVCE

标签: c++ boost boost-python


【解决方案1】:

我发现了我的错误,问题是我在 .h 文件中定义了一个析构函数,但后来我没有实现它。希望对某人有所帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-05
    • 1970-01-01
    • 2011-02-20
    • 2017-11-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多