Quantcast
Channel: ActiveState Community Site - ActivePython discussion
Viewing all articles
Browse latest Browse all 75

undefined symbol: PyInt_FromLong

$
0
0

Getting a strange problem with Python on Ubuntu (and maybe other Linux variants)

System has ActiveState Python 2.6.7 installed:

# Python version 2.6.7 (r267:88850, Jun 27 2011, 02:41:40)
[GCC 4.0.2 20051125 (Red Hat 4.0.2-8)] for linux2

I have Python embedded into a C++ app. It is linked statically (as I can't see any libpython dynamic link libraries.

Basically I can't seem to import the math library:

>>> from math import *
Traceback (most recent call last):
File "", line 1, in
ImportError: /opt/ActivePython-2.6/lib/python2.6/lib-dynload/math.so: undefined symbol: PyInt_FromLong
>>>

OK, I have found a solution. The linker option '-Wl,--export-dynamic' needs to be set so othat the compiler exports the whole symbol table from the statically linked python lib, not just the ones needed by the application itself. Then any shared libs that subsequently get loaded and have a reference to that symbol will find it defined.

This raises a second question though: I had assumed I'd just need to statically link to libpython2.6 and then the user had a complete python interpreter. But this is not the case, as 'import math' is looking for a shared lib in my AS Python directory, sigh.

Q1: how does it know where to look - is this hardcoded into the static lib, so that the application will only work if there is a file at the hardcoded path '/opt/ActivePython-2.6/lib/python2.6/lib-dynload/math.so' present?

Q2: What happens if the user has say AS Python 2.7 installed instead? Will import math fail?

Q3: Is there any way of avoiding the need for the user to have an AS installed Python e.g. by shipping the shared libs seperately???


Viewing all articles
Browse latest Browse all 75

Trending Articles