SWIG Attribute Error: module has no attribute 'delete_...'

SWIG Attribute Error: module has no attribute 'delete_...'

一段时间以来,我一直在努力让它发挥作用。我正在尝试将大量 c++ classes 包装在 swig 中,但我什至无法让第一个工作。错误在底部。这是我的接口文件,setup.py 和 class 文件。

界面

//This file is automatically generated from "build_swig_files.py
//Makes changes to build_swig_files.py to edit jcm.i
%module jcm
%{
#include "jtag/GenericJTAGDevice.h"

typedef unsigned int u32;
%}

class GenericJTAGDevice {
 public:

  virtual ~GenericJTAGDevice();
  GenericJTAGDevice(int irLength, int idCode);

  unsigned int getIrLength();

  unsigned int getIdCode();

 private:
  unsigned int idCode;

  unsigned int irLength;
};
typedef unsigned int u32;
%include <std_string.i>
using std::string;

%include "cpointer.i"
%pointer_functions(u32, u32p);

%include "carrays.i"
%array_class(u32, u32a);

%include "std_vector.i"
namespace std {
    %template(IntVector) vector<int>;
}

setup.py

from distutils.core import setup, Extension


jcm_sources = [
    "jcm.i",
    "/root/git/jcm/jcm_source/base/src/jtag/GenericJTAGDevice.cpp"
]

jcm_module = Extension('_jcm', 
                        sources=jcm_sources,
                        swig_opts=[ '-I/root/git/jcm/jcm_source/base/include',
                                    '-I/root/git/jcm/jcm_source/base/include/jtag',
                                    '-I/root/git/jcm/jcm_source/base/include/util',
                                    '-I/root/git/jcm/jcm_source/base/include/xilinx',
                                    '-c++'],
                        include_dirs=[  '/root/git/jcm/jcm_source/base/include',
                                        '/root/git/jcm/jcm_source/base/include/jtag',
                                        '/root/git/jcm/jcm_source/base/include/util',
                                        '/root/git/jcm/jcm_source/base/include/xilinx'],
                        libraries=['supc++'])

setup (name = 'jcm', version = '0.3', author = 'BYUCCL', ext_modules = [jcm_module], py_modules = ["jcm"])

Class Header

#ifndef GENERIC_JTAG_DEVICE_H
#define GENERIC_JTAG_DEVICE_H

#include <string>
#include <vector>

//#include "JTAGDevice.h"
using namespace std;

/**
 * @brief Basic implementation of a JTAGDevice
 *
 * \class GenericJTAGDevice
 *
 **/
class GenericJTAGDevice {
 public:

  virtual ~GenericJTAGDevice();

  GenericJTAGDevice(int irLength, int idCode);

  unsigned int getIrLength();

  unsigned int getIdCode();

 private:
  unsigned int idCode;

  unsigned int irLength;
};

#endif  // GENERIC_JTAG_DEVICE_H

这里是错误:

>>> import sys
>>> sys.path.insert(0, '/root/git/JCM/jcm_source/python/swig')
>>> import jcm
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/root/git/jcm/jcm_source/python/swig/jcm.py", line 64, in <module>
    class GenericJTAGDevice(object):
  File "/root/git/jcm/jcm_source/python/swig/jcm.py", line 67, in GenericJTAGDevice
    __swig_destroy__ = _jcm.delete_GenericJTAGDevice
AttributeError: module '_jcm' has no attribute 'delete_GenericJTAGDevice'

我已经在接口文件中尝试了几个变体,例如没有完整的 class 定义而只是执行 %include GenericJTAGDevice.h。我感觉它与虚拟析构函数有关,但我不知道如何解决这个问题,因为我需要析构函数。

编辑:我尝试使用另一个 class,它做了同样的事情。所以也许我对接口文件的理解有误。

编辑:我 运行 是 python3 setup.py build

所以我之前在下面的link中看到了答案,但没明白它在说什么。基本上,我构建 swig 的过程不包括制作新的 _jcm.so。所以几乎第一次我 运行 就是这样,之后我对 .i 或代码或 setup.py 所做的所有更改都没有任何意义,因为 _jcm.so 是'被重写。在我的例子中,我从我的 make 文件中 运行 一个“make clean”,它删除了 _jcm.so。之后我再次构建 _jcm.so,然后是 运行 setup.py.

简单,但很难找到。

http://swig.10945.n7.nabble.com/Req-module-object-has-no-attribute-delete-TSP-CA-td2271.html