SWIG包装器在类名中添加了new_前缀,但无法获取类方法
SWIG wrapper adding new_ prefix to the class name and unable to get class method
我已经为简单的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更容易解决。
相关文章:
- 如果C++类在类方法中具有动态分配,但没有构造函数/析构函数或任何非静态成员,那么它仍然是POD类型吗
- 在静态库中嵌入类方法
- 如何制作一个将函数作为参数的类方法
- 从父类方法返回子类对象
- 使用用户定义的参数调用future/async并调用类方法
- 重载类方法的不明确调用
- 单独定义模板化嵌套类方法的正确语法
- 绑定派生类方法C++从实例范围之外的分隔 std::function 变量调用
- 如何访问由共享指针保存的类方法?
- 将子类方法声明为基类的友元
- 我的模板类方法返回错误类型?
- Qt将信号与另一个类方法连接
- 我无法使用C++指针指向类方法返回的 std::vector
- 如何在友元函数中使用静态成员而不添加前缀 [类名]::
- 如何在成为指向基类的指针后保留对子类方法的使用?
- 检查类方法中是否(此 == nullptr)
- 从基类实例调用派生类方法而不进行强制转换
- 函数从唯一代码调用正确的子类方法
- C++ - 如何在不静态的情况下将回调绑定到类方法?
- C++ |DLL / EXE - 如何从导出的类调用另一个类方法?