示例.h:#ifndef EXAMPLE_H
#define EXAMPLE_H
class Math {
public:
int pi() const;
void pi(int pi);
private:
int _pi;
};
#endif
示例.cpp:#include "example.h"
int Math::pi() const {
return this->_pi;
}
void Math::pi(int pi) {
this->_pi = pi;
}
示例swig:%module example
%{
#define SWIG_FILE_WITH_INIT
#include "example.h"
%}
%include "example.h"
然后使用以下方法生成包装器“example.py”和“example_wrap.c”:swig -python example.swig
当我尝试使用以下方法编译包装类时:g++ -fPIC -c example.cpp example_wrap.c -I/usr/local/include/python2.6/
我得到以下错误:example_wrap.cpp: In function "PyObject* Swig_var_Math_get()":
example_wrap.cpp:2725: error: expected primary-expression before "void"
example_wrap.cpp:2725: error: expected ")" before "void"
错误在以下行:pyobj = SWIG_NewPointerObj(SWIG_as_voidptr(&Math), SWIGTYPE_p_class, 0 );
#define SWIG_as_voidptr(a) (void *)((const void *)(a))
这是生成包装类example_wrap.c的正确方法吗?