ctypes加载具有依赖项的c共享库 [英] ctypes loading a c shared library that has dependencies

查看:93
本文介绍了ctypes加载具有依赖项的c共享库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Linux上,我有一个依赖于其他库的c共享库. LD_LIBRARY_PATH已正确设置为允许链接程序加载所有库.当我这样做时:

On Linux, I have a c shared library that depends on other libs. LD_LIBRARY_PATH is properly set to allow the linker to load all the libraries. When I do:

libgidcwf    = ctypes.cdll.LoadLibrary(libidcwf_path)

我收到以下错误:

Traceback (most recent call last):
  File "libwfm_test.py", line 12, in <module>
    libgidcwf    = ctypes.cdll.LoadLibrary(libidcwf_path)
  File "/usr/lib/python2.5/ctypes/__init__.py", line 431, in LoadLibrary
    return self._dlltype(name)
  File "/usr/lib/python2.5/ctypes/__init__.py", line 348, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: path-to-my-lib/libwav.so: undefined symbol: ODBCGeneralQuery

似乎LD_LIBRARY_PATH在这里无效. 有没有办法让这些依赖库可加载"?

It seems that LD_LIBRARY_PATH has no effect here. Is there a way to have these dependency library "loadable" ?

预先感谢您的帮助.

推荐答案

似乎libwav.so并未声明它依赖于定义ODBCGeneralQuery的库.尝试运行ldd path-to-my-lib/libwav.so,看看是否缺少某些内容.如果这是您要构建的共享库,则应为库代码使用的每个库将-llibname添加到链接命令(类似于gcc -shared -o libwav.so a.o b.o c.o的链接).原始共享库以这种方式引用的任何其他库也应自动加载.

It would seem that libwav.so does not declare it's dependency on the library defining ODBCGeneralQuery. Try running ldd path-to-my-lib/libwav.so and see if there's something missing. If this is a shared library that you are building you should add -llibname to the linking command (the one that is something like gcc -shared -o libwav.so a.o b.o c.o) for each library that the library's code uses. Any other libraries referenced by the original shared library in this way should automatically be loaded as well.

这篇关于ctypes加载具有依赖项的c共享库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆