I’m new to Panda3D, though I’m not new to C/C++ or Python. I’m trying to use interrogate.exe to make a library available to python.
The library has 4 header files, an export lib and a dll. When I try to run interrogate on the main header file I just get a syntax error:
interrogate -oc MoMo.c -od MoMo.in -python-native MoMo.h
*** Error in MoMo.h near line 107, column 45:
parse error
Error parsing file: ‘MoMo.h’
The line it is complaining about is a function prototype:
GTek_ReturnValue MOMO_API MoMo_Initialize( MoMo_Api* pApi );
It is complaining about the MoMo_Api type.
I have looked at the docs and they are pretty sparse at best. There isn’t anything there that tells you what to look for if something goes wrong. What am I missing?
Hmmm, I didn’t see a -v option described in the help from running:
interrogate.exe -h
Anyway this is what I got:
interrogate -v -oc MoMo.c -od MoMo.in -python-native MoMo.h
Reading MoMo.h
Reading MoMoTypes.h
*** Warning in MoMo.h near line 107, column 27:
Not a type: dllimport
*** Error in MoMo.h near line 107, column 45:
parse error
Error parsing file: ‘MoMo.h’
MoMo.h includes MoMoTypes.h and at the bottom of it we have: #ifndef MOMO_API #define MOMO_API __declspec(dllimport) #endif
so that’s probably what it is complaining about with regards to “Not a type: dllimport”. It looks like interrogate is tripping over the MOMO_API define when parsing the function prototype.
Yes, that’s not a standard C++ syntax; it’s a Microsoft extension. Interrogate only speaks standard C++.
You will have to protect the MOMO_API definition, for instance with #ifndef CPPPARSER (since CPPPARSER is generally defined on the command line when running interrogate).
and I still get the exact same error about dllimport not being a type. I added -DCPPPARSER to the command line, and it doesn’t complain about dllimport, but it still gives a ‘parse error’ at the same location as before:
interrogate -v -DCPPPARSER -oc MoMo.c -od MoMo.in -python-native MoMo.h
Reading MoMo.h
Reading MoMoTypes.h
*** Error in MoMo.h near line 107, column 45:
parse error
Error parsing file: ‘MoMo.h’
Actually, I doubt this will be your only error. Attempting to parse a new foreign header file with interrogate usually gives large numbers of errors. Usually we don’t use interrogate to directly instrument foreign libraries; instead, we write a series of wrapper functions or classes that integrate with Panda, and we use interrogate to instrument those classes.
For instrumenting a foreign library, you might be better off using a tool that’s more designed for this purpose, such as SWIG or Boost. But interrogate can work too; for instance, we do use interrogate to directly instrument the tinyxml library.