undefined symbols when linking Python into a shared library

Michael Neuroth michael.neuroth at freenet.de
Tue Mar 5 17:03:33 EST 2002


Hello to all python experts,

I have a question about embedding Python in an application.
To be more precisely, I want to create a shared library which
holds the python interpreter and some other functions registered
at the Python interpreter (I used SWIG for that task). This
shared library (or DLL) will be loaded dynamically from an
application to support Python as script language.

This way works well for Windows and (for simple scripts which
do not load other modules) also for Linux.

Unfortunately I get an "undefined symbol" error when I try to
load other modules with the import statement on Linux.
When I try to laod Tkiter in a simple test script, I get this
error message on stderr from the embedded python interpreter:



  Traceback (most recent call last):

    File "<string>", lind 2, in ?

    File "/usr/lib/python2.1/lib-tk/Tkinter.py", line 35, in ?

      import _tkiter # If this fails your Python my not be configured for Tk

  ImportError: /usr/lib/python2.1/lib-dynload/_tkiter.so: undefined symbol: _Py_NoneStruct





I link libpyhton.a into the shared library, I tried also to link
with the option -Xlinker -export-dynamic, as told by the python
documentation (section:Extending and Embedding the Python Interpreter,
5.6 Linking Requirements). The shared library is a little bit lager,
but the resulting error is the same. How can I verify, that this
symbols are in the shared library?

I have no such "undefined symbol" problems, when I embed the python
interpreter into the application directly (with the option:
-Xlinker -export-dynamic).

What is the magic option to solve that (linker?) problem?
Has someone succeded to create a shared library with the pyhton
interpreter which successfully loads other modules?

Any help is welcome. Thank you in advance.


   Michael.


PS:
The appliation which I'm talking about is MinDia, an OpenSource
(multiplatform)
program for slide shows (with rollei diaprojectos), written in C++ and
with Qt.
The homepage and the sourcecode for MinDia can be found at sourceforge:

  http://mindia.sourceforge.net

(The error can be reproduced when loading and running the sample script
_tktest.py)

----------------------------------------------------------------------

  Michael Neuroth,

  e-mail: michael.neuroth at freenet.de

----------------------------------------------------------------------





More information about the Python-list mailing list