weird embedding problem

D

DavidM

Hi all,

I'm embedding python in a C prog which is built as a linux shared lib.

The prog is linked against libpython, and on startup, it calls
Py_Initialize().

The prog imports a pure-python script. The script starts up ok, but when
it imports the 'math' module, the import fails with:

Traceback (most recent call last):
File "/home/david/work/video/myprogs/dvedit/test/frei0rfx1.py", line 10, in <module>
import math
ImportError: /usr/lib/python2.5/lib-dynload/math.so: undefined symbol: PyExc_ValueError
Failed to import math

Any ideas of how to work around this?

Please note - the program I'm writing *must* be built as a shared lib, so
the usual practice of 'extend, don't embed' is just not an option here.

Thoughts?

Cheers
D
 
G

grbgooglefan

Hi all,

I'm embedding python in a C prog which is built as a linux shared lib.

The prog is linked against libpython, and on startup, it calls
Py_Initialize().

The prog imports a pure-python script. The script starts up ok, but when
it imports the 'math' module, the import fails with:

Traceback (most recent call last):
File "/home/david/work/video/myprogs/dvedit/test/frei0rfx1.py", line 10, in <module>
import math
ImportError: /usr/lib/python2.5/lib-dynload/math.so: undefined symbol: PyExc_ValueError
Failed to import math

Any ideas of how to work around this?

Please note - the program I'm writing *must* be built as a shared lib, so
the usual practice of 'extend, don't embed' is just not an option here.

Thoughts?

Cheers
D

the math module above is failing to load because of: "undefined
symbol: PyExc_ValueError"
You may have to import some other module before loading math.
Try doing nm on libraries in /usr/lib/python2.5/lib-dynload & see
which one has this symbol (a function) in defined state ("T").

Also, verify if your script works fine out of the C program - may be
at python prompt.
 
G

Graham Dumpleton

Hi all,

I'm embedding python in a C prog which is built as a linux shared lib.

The prog is linked against libpython, and on startup, it calls
Py_Initialize().

The prog imports a pure-python script. The script starts up ok, but when
it imports the 'math' module, the import fails with:

Traceback (most recent call last):
File "/home/david/work/video/myprogs/dvedit/test/frei0rfx1.py", line 10, in <module>
import math
ImportError: /usr/lib/python2.5/lib-dynload/math.so: undefined symbol: PyExc_ValueError
Failed to import math

Any ideas of how to work around this?

Please note - the program I'm writing *must* be built as a shared lib, so
the usual practice of 'extend, don't embed' is just not an option here.

Thoughts?

Are you actually linking your C program against the Python library?

Graham
 
G

Graham Dumpleton

Yes. Refer OP:

What was the compiler link line you used for your program/shared
library then?

Have you confirmed using 'ldd' command that your program/shared
library do actually link against libpython?

Your original description is confusing. You say your program is built
as a shared library. Can you properly explain the full process you are
using to build your code and if you are producing a shared library for
your program how then is that shared library being used with an actual
executable? Be specific about where the program main() is located?

Some platforms don't necessarily find symbols from shared library 'A'
linked against a program executable if the main() is actually obtained
from a shared library 'B" linked to the same program and where the
symbols required from 'A' are only used in 'B'. What is required is to
link library 'A' against library 'B'.

Graham
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,278
Latest member
BuzzDefenderpro

Latest Threads

Top