您好,感谢您的帮助!在
我正在编写一个Python包装器(Sigg 2 + Python 2.7),用于C++代码。C++代码中有我需要在Python包装器中访问的Type。不幸的是,我在执行Python代码时遇到以下错误:
tag = CNInt32(0)
NameError: global name 'CNInt32' is not defined
我查看了SWIG文档的第5.3.5节,其中解释了size_t是typedef,但我不能让它起作用。在
以下是重现错误的简单代码:
/* File : example.cpp */
#include "example.h"
#include <iostream>
using namespace std;
/* I'm a file containing use of typedef variables */
ExampleClass::ExampleClass() {
}
ExampleClass::~ExampleClass() {
}
void ExampleClass::printFunction (int value) {
cout << "Value = "<< value << endl;
}
void ExampleClass::updateInt(CNInt32& var) {
var = 10;
}
/* File : example.i */
%module example
typedef int CNInt32;
%{
#include "example.h"
%}
%include <windows.i>
%include "example.h"
# file: runme.py
from example import *
# Try to set the values of some typedef variables
exampleObj = ExampleClass()
exampleObj.printFunction (20)
var = CNInt32(5)
exampleObj.updateInt (var)
再次感谢你的帮助。在
桑托什
我成功了。我不得不在接口文件中使用类型映射,见下文:
-非常感谢Swig邮件列表上的“David Froger”。
-另外,感谢doctorlove的初步提示。在
然后在python文件中:
^{pr2}$再次感谢!
桑托什
相关问题 更多 >
编程相关推荐