提升 Python 导入失败,未定义包装类的符号

Boost Python import fails, symbol of wrapped class not defined

本文关键字:包装类 符号 未定义 Python 导入 失败 提升      更新时间:2023-10-16

我在当前项目中使用 boost python 时遇到问题。当我尝试在python 3.6中导入生成的模块时,显示以下错误:ImportError:PythonTrackWrapper.so:未定义的符号:_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);
}

CMakeList.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})

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

谢谢!

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