468,140 Members | 1,456 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,140 developers. It's quick & easy.

weird embedding problem

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
Dec 7 '07 #1
4 2459
On Dec 7, 2:01 pm, DavidM <nos...@nowhere.comwrote:
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.
Dec 7 '07 #2
On Dec 7, 5:01 pm, DavidM <nos...@nowhere.comwrote:
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

Dec 7 '07 #3
On Fri, 07 Dec 2007 00:53:15 -0800, Graham Dumpleton wrote:
Are you actually linking your C program against the Python library?
Yes. Refer OP:
>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().
Dec 7 '07 #4
On Dec 7, 11:44 pm, DavidM <nos...@nowhere.comwrote:
On Fri, 07 Dec 2007 00:53:15 -0800, Graham Dumpleton wrote:
Are you actually linking your C program against the Python library?

Yes. Refer OP:
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().
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
Dec 8 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Alicia Haumann | last post: by
2 posts views Thread by Roose | last post: by
2 posts views Thread by Lyn | last post: by
13 posts views Thread by Krzysztof Bartosiewicz | last post: by
6 posts views Thread by mistabean | last post: by
27 posts views Thread by didacticone | last post: by
1 post views Thread by gcdp | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.