undefined symbol: PyExc_ImportError when embedding Python in C

匿名 (未验证) 提交于 2019-12-03 00:56:02

问题:

I'm developing a C shared library that makes a call to a python script. When I run the application I get this error:

Traceback (most recent call last):   File "/home/ubuntu/galaxy-es/lib/galaxy/earthsystem/gridftp_security/gridftp_acl_plugin.py", line 2, in      import galaxy.eggs   File "/home/ubuntu/galaxy-es/lib/galaxy/eggs/__init__.py", line 5, in      import os, sys, shutil, glob, urllib, urllib2, ConfigParser, HTMLParser, zipimport, zipfile   File "/usr/lib/python2.7/zipfile.py", line 6, in      import io   File "/usr/lib/python2.7/io.py", line 60, in      import _io ImportError: /usr/lib/python2.7/lib-dynload/_io.so: undefined symbol: PyExc_ImportError 

If I try to import the module io from console works fine instead:

Python 2.7.1+ (r271:86832, Apr 11 2011, 18:13:53)  [GCC 4.5.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import galaxy.eggs >>>  

During the compilation of library I've used this compiler option as suggest here : Embedding python in C, undefined symbol: PyExc_ImportError In addition I've added also the compiler options obtained from python-config --includes|--libs|--cflags|--ldflags

Here you can find the log of makefile of library http://pastebin.com/348rhBjM

Thanks a lot, any help will be apreciated.

回答1:

I've found the solution. Maybe can be useful for someone else. It's a bug of python as written here http://mail.python.org/pipermail/new-bugs-announce/2008-November/003322.html I've used the solution posted here http://www.cilogon.org/gsi-c-authz



回答2:

I use such workaround: explicit linking of plugins from lib-dynload directory (it's simply, then explicit dlopen in code). Example with datetime.so:

cmake:

SET ( CMAKE_SHARED_LINKER_FLAGS "/usr/lib/python2.7/lib-dynload/datetime.so" ) 

or just add /usr/lib/python2.7/lib-dynload/datetime.so as linker parameter to gcc in command line:

g++ -shared -o libfoo.so foo.o -lbar -lzab /usr/lib/python2.7/lib-dynload/datetime.so 


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!