I’m having some trouble using interrogate to generate a simple HelloWorld module. I’m mostly trying to follow the tutorial from panda3d.org/manual/index.php/Interrogate. Here is my header file:
This seems to go alright, and I get a test.so file in that directory. Then I try to run python and import my new class:
Python 2.5.2 (r252:60911, Oct 5 2008, 19:24:49)
[GCC 4.3.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from test import HelloWorld
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: dynamic module does not define init function (inittest)
>>>
Hmm, well, one problem is that you have no PUBLISHED methods defined in your class (your only method is just declared public, not PUBLISHED, so interrogate won’t see it).
In order to define the PUBLISHED macro properly, you will need to include at least dtoolbase.h, which might in turn have other requirements. The generated interrogate file will require including this file, too.
Another problerm is that you need to specify “-library test” on the interrogate_module command line, to tell it the name of the library you are generating.
I tried your suggestions but it didn’t make a difference. I did notice a footnote on ( panda3d.org/manual/index.php/Interrogate ). In the panda3d source, there are skeleton classes that I should use to help me learn interrogate. After downloading the source, I tried following the instructions on the interrogate manual. I couldn’t get past the first step:
~/panda3d-1.5.4/panda/src/skel$ interrogate -oc basicSkel.cxx -od basicSkel.in -python-native basicSkel.h
*** Error in basicSkel.I near line 22, column 13:
syntax error, unexpected IDENTIFIER, expecting '{' or ';' or ':' or '='
Error parsing file: 'basicSkel.h'
This is unmodified code from the website. Am I missing something here?
Probably not what you want, because in -python mode, C++ objects and methods will be converted into an object handle and a list of independent Python functions (just like C) instead of being converted into true Python objects.
So the fundamental problem here is that interrogate has been tightly developed in conjunction with Panda, and it is primarily designed to be used within the existing Panda build environment. It should theoretically be possible to use it outside of Panda’s build environment, but you will have to learn the exact combination of parameters and header files etc. that it will require.
The easiest way to learn this is to start within Panda’s build environment in the first place. Interrogate works fine there. If that works to your satisfaction, you might as well stay there. Or, if you really want to be completely isolated from Panda’s build environment, at least you will be empowered to figure out how to make that happen.
The skel directory that you refer to is built automatically by both the makepanda and ppremake build systems. Try building it with one of those, and you’ll see the proper command lines that are passed to interrogate and interrogate_module.
Have you tried my suggestion of examining the exact commands generated by makepanda or ppremake to run interrogate for basicSkel? For instance, I think you’re missing a separate call to interrogate_module, which generates the part of the code wrappers that makes your .pyd importable to Python.
I don’t understand what you mean by this:
That sounds like trouble–without the .I file, you’ll have no function body for the inline methods. How can it possibly build without that? And are you saying that the project doesn’t build if you leave it in? Why not, what is the error message? (You haven’t attempted to add the .I file to your project, have you? That would be a mistake.)
Your right. If you add the .I file it builds fine. I thought it didn’t exist earlier and so thought it wasn’t required.
But I still am not able to solve the problem of:
Also,
I didn’t understand what you meant by this clearly. I went through the documentation of makepanda and ppremake and am still confused about how to use it. Should i use makepanda - everything and look at a log file?
[/quote]
I tried to use similar commands on interrogate to build it but it still couldn’t get: from libBasicSkel import BasicSkel to work. I wonder if there is another way to do it.
We are actually looking for a way to include these third party AI libraries (written in C++) into the Panda python framework. So is rebuilding the version of Panda with these dlls the only way to go about it? I looked through the video tutorial too but that’s only got me this far.
b[/b] This created wrapper.cxx and wrapper_module.cxx. I compiled them and created the object files which I included in my Visual Studio linker and include directory (both, since I wasn’t sure where to put it exactly to include it).
b[/b] Then I made the dll and lib files by building it with changes in the configuration properties in Visual Studio.
b[/b] I took this dll and lib file and pasted them in my python project directory. I renamed the dll to pyd. I also had to rename the dll and lib files from (WrapperTry.dll and WrapperTry.lib) to (libBasicSkel.pyd and libBasicSkel.lib) since I was getting the init error mentioned eariler in the post. (This seemed to solve it…I tried this as in wrapper.cxx I found an initlibSkel() created so I assumed that python references it from the filename?)
Now when I do: from libBasicSkel import BasicSkel it gives the error saying
ImportError: cannot import name BasicSkel
Have i missed any critical steps or is there an alternate route I should take to get this to work ?
Also are you sure the class has “INLINE” methods (and that it’s including one of the Panda headers so that you make sure INLINE is even defined)? You could also try putting interrogate in promiscuous mode.
That sounds generally right. You are correct that Python determines the name of the init function based on the filename. Note also that that .lib file is not required for Python.
What symbols do you have in libBasicSkel?
import libBasicSkel
dir(libBasicSkel)
In your generated wrapper.cxx file, do you have code that looks vaguely like this?
That’s not the part of wrapper.cxx I was looking for; I was looking for the part that defines the BasicSkel method, or any part of the BasicSkel class. If that part is missing, then it looks like interrogate has run successfully, but did not decide to generate wrappers for your BasicSkel class.
Are you using the standard basicSkel.h file from the distribution? Note that you misspelled the filename on the command line; you wrote “BasicSkel.h” instead of “basicSkel.h”, though I don’t think this matters.
You shouldn’t have /usr/include on the interrogate command line. That’s asking for trouble.
Your interrogate command line works fine for me (with some modifications for my local path settings) when run on the standard basicSkel.h file, so there must be something else in your environment or something that’s wrong. You can put -v on the interrogate command line; that might give some more insight. When I do this, I get:
fisheye:~/player/panda/src/skel> interrogate -v -D__inline -DCPPPARSER -D__cplusplus -S $DTOOL/built/include/parser-inc -I $DTOOL/built/include -I $PANDA/built/include -oc wrapper.cxx -od wrapper.in -fnames -string -refcount -assert -python-native -module BasicSkel -library libBasicSkel BasicSkel.h
Reading BasicSkel.h
Reading /home/drose/player/panda/built/include/pandabase.h
Reading /home/drose/player/dtool/built/include/dtoolbase.h
Reading /home/drose/player/dtool/built/include/dtool_config.h
Reading /home/drose/player/dtool/built/include/dtoolsymbols.h
*** Warning in /home/drose/player/dtool/built/include/dtoolbase.h near line 100, column 2:
Cannot find assert.h
*** Warning in /home/drose/player/dtool/built/include/dtoolbase.h near line 114, column 2:
Cannot find sys/types.h
Reading /home/drose/player/dtool/built/include/parser-inc/malloc.h
*** Warning in /home/drose/player/dtool/built/include/dtoolbase.h near line 134, column 2:
Cannot find io.h
*** Warning in /home/drose/player/dtool/built/include/dtoolbase.h near line 142, column 2:
Cannot find string.h
*** Warning in /home/drose/player/dtool/built/include/dtoolbase.h near line 154, column 2:
Cannot find minmax.h
Reading /home/drose/player/dtool/built/include/parser-inc/stdtypedefs.h
Reading /home/drose/player/dtool/built/include/dtoolbase_cc.h
Reading /home/drose/player/dtool/built/include/parser-inc/iostream
Reading /home/drose/player/dtool/built/include/parser-inc/string
Reading /home/drose/player/dtool/built/include/parser-inc/stdtypedefs.h
Reading /home/drose/player/panda/built/include/pandasymbols.h
Reading basicSkel.I
The warnings about missing system header files is normal.
*Note: I also tried including C:\Panda3D-1.6.2\include\parser-inc with the same output.
Output:
[b]
The same output as yours all the way till the end where i get:
Attempt to use undefined namespace: std
Error in dtoolbase_cc.h ( line 103 )
Symbol ios is not a known scope in
Error in dtoolbase_cc.h ( line 103 )
parse error
Error parsing file: 'basicSkel.h'
I didn’t mean to confuse you. My own build environment is very different from the standard 1.6.2 SDK environment. Pay no attention to my variables named $DTOOL and $PANDA and such; that’s particular to my own environment. But, yeah, those are roughly equivalent to C:\Panda3D-1.6.2 .
Looks like you’ve got another typo on your interrogate line: you said “-DCPPARSER” instead of “-DCPPPARSER”.