DoubleLi

qq: 517712484 wx: ldbgliet

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
  4737 随笔 :: 2 文章 :: 542 评论 :: 1615万 阅读
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

rb report at bugs.python.org
Wed Nov 26 10:13:39 CET 2008

 


New submission from rb <rb-oss-1 at justgohome.co.uk>:

Python cannot be embedded in shared library due to dependency problems
with lib-dynload.

I am implementing a shared library (in C) that implements a specific API
as a dynamically loadable plugin to an application. To implement this
library, I am calling out to Python via the C API.

When my code tries to load a Python module, it fails. This is because
lib-dynload/time.so (for example) cannot resolve symbols that are in
libpython2.5.so because it never looks there.

In this test case I'm trying to import "time", but it seems to fail on
other modules too - presumably anything that is in lib-dynload. It also
fails if I import a pure Python module that then tries to import time.

The error produced is: ImportError:
/usr/lib/python2.5/lib-dynload/time.so: undefined symbol: PyExc_ValueError

>From LD_DEBUG:
     29682:file=/usr/lib/python2.5/lib-dynload/time.so [0];  needed by 
/usr/lib/libpython2.5.so.1.0 [0]
...
     29682:relocation processing: /usr/lib/python2.5/lib-dynload/time.so
     29682:symbol=PyExc_ValueError;  lookup in file=./myprog [0]
     29682:symbol=PyExc_ValueError;  lookup in file=/lib/libdl.so.2 [0]
     29682:symbol=PyExc_ValueError;  lookup in file=/lib/libc.so.6 [0]
     29682:symbol=PyExc_ValueError;  lookup in
file=/lib64/ld-linux-x86-64.so.2 [0]
     29682:symbol=PyExc_ValueError;  lookup in 
file=/usr/lib/python2.5/lib-dynload/time.so [0]
     29682:symbol=PyExc_ValueError;  lookup in file=/lib/libm.so.6 [0]
     29682:symbol=PyExc_ValueError;  lookup in file=/lib/libpthread.so.0 [0]
     29682:symbol=PyExc_ValueError;  lookup in file=/lib/libc.so.6 [0]
     29682:symbol=PyExc_ValueError;  lookup in
file=/lib64/ld-linux-x86-64.so.2 [0]
     29682:/usr/lib/python2.5/lib-dynload/time.so: error: symbol lookup
error: 
undefined symbol: PyExc_ValueError (fatal)


$ nm -D /usr/lib/libpython2.5.so.1|grep PyExc_ValueError
000000000033a7e0 D PyExc_ValueError



$ ldd /usr/lib/python2.5/lib-dynload/time.so
libm.so.6 => /lib/libm.so.6 (0x00002afe014c9000)
libpthread.so.0 => /lib/libpthread.so.0 (0x00002afe0174a000)
libc.so.6 => /lib/libc.so.6 (0x00002afe01967000)
/lib64/ld-linux-x86-64.so.2 (0x0000555555554000)



I am told that the problem is that lib-dynload/*.so should depend on
libpython2.5.so.1.


Test case attached. mylib.c is the library that I'm implementing reduced
to the problem case. myprog.c is a stub program that loads mylib.c to
demonstrate the problem. The "real" myprog would be any third-party
application that I have no control over that expects to be able to
dlopen() mylib.so and call functions within it.


I have been given the following workaround: in mylib.c, before
PyInitialize() I can call dlopen("libpython2.5.so", RTLD_LAZY |
RTLD_GLOBAL);

This works, but I believe that lib-dynload/*.so should depend on
libpython2.5.so.1 so this hack should not be necessary.

I am using Ubuntu 8.04 with Python version 2.5.2-2ubuntu4.1.

----------
components: Library (Lib)
files: mylib.c
messages: 76454
nosy: rb
severity: normal
status: open
title: Embedding into a shared library fails
type: behavior
versions: Python 2.5
Added file: http://bugs.python.org/file12134/mylib.c

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue4434>
_______________________________________

 

posted on   DoubleLi  阅读(26)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!
历史上的今天:
2022-07-19 李超:WebRTC传输与服务质量
2021-07-19 FFmpeg内存模型与API介绍(notes 2)
2018-07-19 centOS7服务管理与启动流程
2018-07-19 CentOS 6和CentOS 7防火墙的关闭
2018-07-19 linux 系统安装配置 zabbix服务(源码安装)
2018-07-19 zabbix_agentd客户端安装与配置(Linux操作系统)
2018-07-19 zabbix_agentd客户端安装与配置(windows操作系统)
点击右上角即可分享
微信分享提示