undefined symbol: PyObject_GenericGetAttr when trying to embed Python

Rick Ratzel rick.ratzel at scd.magma-da.com
Fri Jun 4 11:02:33 EDT 2004


    You may have to link your app with some additional flags.  You can 
use the distutils module to see which ones you need for loading shared 
objects (like _socket.so) at runtime.  Here is what my Python build for 
Linux needs (from http://elmer.sourceforge.net/PyCon04 ):

 >>> import distutils.sysconfig
 >>> distutils.sysconfig.get_config_var("LINKFORSHARED")
'-Xlinker -export-dynamic'

    Then, simply add -Xlinker -export-dynamic to the link line for the 
embedded Python app and the .so modules should have all the proper 
symbols resolved.  Hope that helps,

-Rick Ratzel

Andreas Jung wrote:
> I am trying to embed Python within a C++ application (Linux, Python2.3.4).
> I am using the example from the example from the "Embeding and 
> Extending" docs.
> This works fine importing a simple module without any imports. However 
> when I add
> an "import urllib" inside the Python script to be imported through my 
> C++ application
> then the import fails:
> 
> Traceback (most recent call last):
>  File "/home/ajung/sandboxes/HR2/hr2_zope_wrapper/hr2_wrapper.py", line 
> 16, in hr2_wrapper
>    import urllib
>  File "/opt/python-2.3.4/lib/python2.3/urllib.py", line 26, in ?
>    import socket
>  File "/opt/python-2.3.4/lib/python2.3/socket.py", line 44, in ?
>    import _socket
> ImportError: /opt/python-2.3.4/lib/python2.3/lib-dynload/_socket.so: 
> undefined symbol: PyObject_GenericGetAttr
> 
> Any ideas?
> 
> Andreas
> 
> 



More information about the Python-list mailing list