Hello and thanks for your help in advance!
I am writing a python wrapper (SWIG 2.0 + Python 2.7) for C ++ code. C ++ code has a typedef that I need to get in the python shell. Unfortunately, I get the following error while executing my Python code:
tag = CNInt32(0)
NameError: global name 'CNInt32' is not defined
I looked through section 5.3.5 of the SWIG documentation explaining the size_t size as a typedef, but I also could not get this to work.
Below is a simpler code to reproduce the error:
C ++ header:
#ifndef __EXAMPLE_H__
#define __EXAMPLE_H__
#include <stdio.h>
#if defined(API_EXPORT)
#define APIEXPORT __declspec(dllexport)
#else
#define APIEXPORT __declspec(dllimport)
#endif
typedef int CNInt32;
class APIEXPORT ExampleClass {
public:
ExampleClass();
~ExampleClass();
void printFunction (int value);
void updateInt (CNInt32& var);
};
#endif
C ++ Source:
#include "example.h"
#include <iostream>
using namespace std;
ExampleClass::ExampleClass() {
}
ExampleClass::~ExampleClass() {
}
void ExampleClass::printFunction (int value) {
cout << "Value = "<< value << endl;
}
void ExampleClass::updateInt(CNInt32& var) {
var = 10;
}
Interface File:
%module example
typedef int CNInt32;
%{
#include "example.h"
%}
%include <windows.i>
%include "example.h"
Python Code:
from example import *
exampleObj = ExampleClass()
exampleObj.printFunction (20)
var = CNInt32(5)
exampleObj.updateInt (var)
Thanks again for your help.
Santos
source
share