首页 > 解决方案 > 使用 boost::noncopyable 时 Python Boost 未定义符号

问题描述

我在使用 boost 和 python3.8 绑定代码时遇到问题

错误

Traceback (most recent call last):
  File "boost-bindings/python_valve_controller.py", line 3, in <module>
    import python_valve_controller
ImportError: /app/boost-bindings/python_valve_controller.so: undefined symbol: _ZTI18ArmouredValveCntrl

模块文件

#include <iostream>
#include "ArmouredValveCntrl.h"
#include <boost/python.hpp>

using namespace boost::python;

BOOST_PYTHON_MODULE(python_valve_controller)
{
    class_<ArmouredValveCntrl, boost::noncopyable>("ArmouredValveCntrl")
        .def("coco_start", &ArmouredValveCntrl::coco_start)
    ;
};

ArmoredValveCntrl.h

#pragma once

#include "coco/runtime.h"

#include "Armour.h"
#include "PArmour.h"
#include "TestValveCntrl.h"

class ArmouredValveCntrl : public coco::BaseMultiThreadedEncapsulatingComponent {
 public:
  ArmouredValveCntrl();

  ~ArmouredValveCntrl();

  void coco_start() override;
  PArmourProvided &client() { return *client_; }
  void set_logger_recursively(coco::StateMachineLogger *logger) override;

 private:
  Armour armour_;
  SimulateValveCntrl testValve_;
  PArmourProvided *client_;
};

我需要使用 boost::noncopyable,否则我会被删除一堆已删除的错误,例如:

/usr/include/boost/python/object/value_holder.hpp:133:13: error: use of deleted function 'ArmouredValveCntrl::ArmouredValveCntrl(const ArmouredValveCntrl&)'
  133 |             BOOST_PP_REPEAT_1ST(N, BOOST_PYTHON_UNFORWARD_LOCAL, nil)
      |             ^
In file included from /app/boost-bindings/python_valve_controller.cpp:5:

使用 boost::noncopyable 是好方法吗?在这种情况下,我该如何修复未定义的符号?

如果没有,我该如何修复所有已删除的错误(参考:使用已删除的函数与 boost::bind)?

标签: c++python-3.xboost-python

解决方案


推荐阅读