4

I am trying to write a plug-in for Audacious Media Player that loads a python module. The python embedding code is from the python-2.6 source(embed/Demo). This compiles with the command line,

gcc -o demo demo.c -lpython2.6 -lm -L/usr/lib/python2.6/config

I added -lpython2.6 -lm -L/usr/lib/python2.6/config to the CC args.

And it loads a Python script which imports pygtk and gtk modules, this works fine.

But after I compile the plug-in(a shared library) the following error occurs(this is not specific for gtk as I found out, it's the same for any python module that uses native libraries)

 Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "./xyz.py", line 7, in <module>
    import gtk
  File "/usr/lib/pymodules/python2.6/gtk-2.0/gtk/__init__.py", line 30, in <module>
    import gobject as _gobject
  File "/usr/lib/pymodules/python2.6/gtk-2.0/gobject/__init__.py", line 26, in <module>
    from glib import spawn_async, idle_add, timeout_add, timeout_add_seconds, \
  File "/usr/lib/pymodules/python2.6/gtk-2.0/glib/__init__.py", line 22, in <module>
    from glib._glib import *
ImportError: /usr/lib/libpyglib-2.0-python2.6.so.0: undefined symbol: PyExc_ImportError

The C code for setting up python interpreter only lacks the PySys_SetArgv call. I tried to fake it but it resulted in the same error!

ismail
  • 46,010
  • 9
  • 86
  • 95
madura
  • 41
  • 1
  • 2

2 Answers2

3

Assuming you are on Linux, you need to add -Xlinker -export-dynamic to the compiler line. This will cause symbols defined in the executable to be available to extension modules.

On other platforms, see whether LINKFORSHARED is set in the Python makefile, and then use the same flags.

Martin v. Löwis
  • 124,830
  • 17
  • 198
  • 235
  • http://pastebin.com/raw.php?i=PXZuhQE3 This is the makefile that I'm using. I tried it, but that didn't resolve the problem. Thanks for the answer! – madura Jan 22 '11 at 11:50
  • @madura: don't use that option for `song_change.so`. Use it for linking `demo` instead. – Martin v. Löwis Jan 22 '11 at 12:11
1

Are you using 64 bit python on Windows? 64 bit python26.Lib is missing some symbols which are available in 32 bit python. Try 32 bit python and your problem should be resolved.