Embedded Python can't "import socket" -- "undefined symbol"
Oleg Broytmann
phd at emerald.netskate.ru
Wed Jul 14 04:58:36 EDT 1999
On 13 Jul 1999, Steven Work wrote:
> I am embedding Python in a C program (on Linux 2.2.x, Debian 2.1), and
> trying to run a script via PyRun_SimpleFile(). "print 'hello, world'"
> works, but "import socket" dies. Can anyone help me find out why?
>
> $ ./testfile
> Traceback (innermost last):
> File "jukebox_xml.py", line 1, in ?
> import socket
> ImportError: /usr/lib/python1.5/lib-dynload/socketmodule.so:
> undefined symbol: _Py_NoneStruct
> $ nm testfile | grep NoneStruct
> 0808ecfc D _Py_NoneStruct
>
> And of course "import socket" works fine in /usr/bin/python.
_Py_None_Struct (and other symbols) should be exported from your main
program to link successfully. You haven't mention your OS and compiler, but
I think it is ELF-based UNIX, and probably gcc, right?
Add -Wl,-E to compiler flags. This means "pass -E to ld linker", which
in turn means "export all symbols from main linked module".
"man ld" for detalils on -E flag.
> --
> Steven Work
> Renaissance Labs
> steve at renlabs.com
> 360 647-1833
Oleg.
----
Oleg Broytmann Netskate/Inter.Net.Ru phd at emerald.netskate.ru
Programmers don't die, they just GOSUB without RETURN.
More information about the Python-list
mailing list