Jump to content
  • Advertisement
Sign in to follow this  
Basss

SWIG doesn't produce .py file

This topic is 2999 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello, I've 2 c++ classes that I try to call from python by using swig. Now when I use "swig -c++ -python -classic myclass/myclass.i" and then compile all the cc files and the generated wrapper with "g++ -c -Wall -O4 -fPIC -I/usr/include/python2.6 *.cc myclass_wrap.cxx" and then link it with: "g++ -shared *.o -o _myclass.so" there is no .py file generated although it is necessary for importing the python module. The Internet tutorial doesn't seem to cover this. Does anybody know how to generate the .py file? Thanks, Basss

Share this post


Link to post
Share on other sites
Advertisement
Have you tried renaming the .so file to .py? I haven't used python for a while but I think it loads native shared libraries directly.

Share this post


Link to post
Share on other sites
No, that doesn't work unfortunately, in the .so file is no valid python code. In some examples they need both a .so and a .py file. But I only get the .so file. :(

Share this post


Link to post
Share on other sites
I just tried compiling a sample extension that comes with Boost.Python. I put the .so file (without renaming) in the same directory as the python file and the extensions gets loaded and works fine. There is no extra file, just the .so file and the python source file that loads the module using import.
If the library is called 'ext.so' you can load it using 'import ext'. import can load both python files and shared libraries.
Do you get any error messages?

Share this post


Link to post
Share on other sites
Yes, just using the .so file was the first thing I tried, but that got me the message that the module could not be found.

However, I just found the .py file, it was in the folder with my sources. For some reason, the .so file ends up in the folder where my executable is, while the .py ends up with the sources... Bit stupid that I didn't see that before.

Now I'm just left with a problem with a struct I use in my class, It can't find that struct when compiling the wrapper for that class (I provide it with the necessary object files). But I guess that is a totally different problem.

Thanks for your help so far!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!