SWIG包装器在类名中添加了new_前缀,但无法获取类方法

SWIG wrapper adding new_ prefix to the class name and unable to get class method

本文关键字:前缀 类方法 获取 new 包装 添加 SWIG      更新时间:2024-09-28

我已经为简单的C++void函数编写了包装器,该函数接受2个字符串参数。由于某些原因,当我试图创建我的类的对象时,我会遇到名称错误";name"我的类名"未定义;。当我尝试创建对象并在创建对象的类名之前指定new_前缀时,但我仍然无法用类似的名称技巧调用我的函数。Bellow接口和类的代码:

%module python_module
%{
#include "python_wrapper.h"
%}
%import std_string.i
%include "python_module.h"

python_wrapper.h

#ifndef PYTHON_WRAPPER_H
#define PYTHON_WRAPPER_H
#include <string>
class Separator
{
public:
Separator();
~Separator();
public:
void separate(const std::string& Path, const std::string& destFolder);
};
#endif

strong文本

#include "python_wrapper.h"
#include <separator.h>
Separator::Separator()
{
}
Separator::~Separator()
{
}
void Separator::separate(const std::string& Path, const std::string& destFolder)
{
::SomeSeparate(assemblyPath, destFolder);
}

我用cmake构建一切。当我在终端中运行时:

python3
>>> from _MyModule import *
>>> separator = Separator()
I'm getting name error : name 'Separator' is not defined.

有人能帮忙吗?

同时,当我给发短信时

>>> separator = new_Separator()

创建对象,但即使在这之后我也无法调用我的函数。

使用pybin11而不是SWIG。对于我的任务来说,这比swig更容易解决。