Loading a Python module fails with the message “unknown symbol”

by

Using the import statement of Python to load a self build module sometimes fails. In my personal experience most of the time the problem was due to unresolved symbols in my .so modules. For QNX and many other POSIX compatible systems like GNU/Linux Python uses dlopen to load the dynamic libraries aka modules.

To have a deeper look at this issue it may help to start Python in more verbose mode using the option -v:

python -vv

The printed messages are listing different attempts to load the required module with different names in different locations. Finally dlopen is called with the .so file named module.so. Afterwards the names of the unknown symbols are shown. An unknown symbol is a reference to a function or method that should be available at runtime but the loading mechanism can not find the required resource.

On QNX some more information about the loading process of dlopen are available. To enable these information use

export DL_DEBUG=1

from the shell or from Python

os.environ['DL_DEBUG'] = ’1′

to get a more verbose dlopen.

To have a look at the specific dynamic .so module it is possible to use the linker ld. Use the option -M or –print-map to print a link map. More options are available from the manual of ld, e.g. the one for GNU ld of the binutils package is available from http://sourceware.org/binutils/docs/ld/index.html.

To ensure that that a dynamic module has no undefined symbols the linker option –no-allow-shlib-undefined may be used. Depending on the build process it may be possible to add the following line to the Makefile:

LDFLAGS+=-Wl,–no-allow-shlib-undefined

About these ads

Tags: , , , , , , ,

One Response to “Loading a Python module fails with the message “unknown symbol””

  1. Bookmarks about Modules Says:

    [...] – bookmarked by 5 members originally found by skbecker on 2008-09-28 Loading a Python module fails with the message “unknown symbol” http://cldoten.wordpress.com/2008/08/28/loading-python-module-fails-with-message-unknown-symbol/ – [...]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


Follow

Get every new post delivered to your Inbox.

%d bloggers like this: