首页 > 编程语言 >Embedding into a shared library fails-- c++ import numpy异常

Embedding into a shared library fails-- c++ import numpy异常

时间:2023-07-19 18:23:46浏览次数:42  
标签:PyExc fails lib -- into 29682 symbol so ValueError

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>
_______________________________________

 

标签:PyExc,fails,lib,--,into,29682,symbol,so,ValueError
From: https://www.cnblogs.com/lidabo/p/17566433.html

相关文章

  • springcloud stream kafka实践
    SpringCloudStream是SpringCloud提供的一个用于构建消息驱动的微服务的框架。它简化了消息系统(如Kafka,rabbitMQ)的使用和集成,使开发者可以更专注于业务逻辑的实现。项目结构如下 一、移入依赖创建一个springbootweb项目引入依赖1<properties>2<java.version>1......
  • PlayWright(二十一)- Pytest插件报告
    1.下载pytest框架有官方的报告pipinstallpytest-html 下载成功,那我们怎么使用呢? 2.使用可以直接在配置文件里使用 在pytest配置文件中,增加命令选项选项:--html=./报告路径/报告⽂件名.html说明:--self-contained-html将CSS⽂件内嵌到报告⽂件中  ......
  • ABP-配置设置
    配置设置ABP遵循的是约定大于配置,作为约定的内容需要在应用程序中进行设置。定义设置在设置之前需要先定义他,由于ABP是模块化的,不同模块都可以拥有自己独立的设置参数,只需要在类中派生SettingDefinitionProvider类//ABP会自动发现并和注册设置的定义publicclassStudentSet......
  • springboot——yaml格式
    ......
  • mybatis的generator 代码生成器(自动生成DAO,PO,XML)
    1.引入插件<!--mybatis代码自动生成插件--><plugin><groupId>org.mybatis.generator</groupId><artifactId>mybatis-generator-maven-plugin</artifactId><......
  • 线性代数4 初等变换、初等矩阵、分块矩阵、方阵行列式
    1.1初等变换和初等矩阵的概念初等变换的概念:初等变换并不是一个运算操作,而是一类对矩阵的操作的统称对于m×n矩阵A:(1)倍乘:对A的某行或某列元素乘上一个非零常数k(2)互换:互换A的某两列或某两行元素的位置(3)倍加:将A的某行或某列元素的k倍加到另一行或列上这三种变换统称为初等(行......
  • maven build 运行unit test失败 process exit code:134
    环境:JDK:17.0.7Springboot:3.1.0Junit:5问题:运行mvncleaninstall时在maven-surefire-plugin:test阶段失败。TheforkedVMterminatedwithoutprperlysayinggoodbye.VMcrashorSystem.exitcalled?dumpfile中的错误:Corruptedchannelbydirectlywriting......
  • 内札萨克蒙古
    谁不想拥有一个说走就走的旅行啊?在每个人的生活中段关于旅行的憧憬,一段说走就走的旅行。古有李白游山玩水,写下“飞流直下三千里,疑是银河落九天”的千古名句,今有梁衡到陕西,写下气势磅礴的壶口瀑布。可以说旅游是从古至今人们最喜欢的一项活动之一,在今年暑假我也要开启属于自己的旅......
  • WPF版本发布流程
    前言使用工具:MicrosoftVisualStudio2012框架版本:.NETFramework4.5一、WPF发布程序的教程方法1.进入项目目录,右键点击属性 (右键:属性=>发布)  2.填写程序发布路径  本地发布选择【文件系统】、填入发布路径即可下一步(可以新建1个文件夹)。3.选择程序文件(发布......
  • Linux中JVM内存调整大小
    linux修改jvm内存大小第一:要修改Linux上JVM的内存大小,可以按照以下步骤进行:1.打开JVM的配置文件,一般是在JVM安装目录下的bin目录中,文件名为java或者jvm.cfg。2.找到-Xmx和-Xms参数,它们分别表示JVM的最大内存和初始内存大小。可以根据需要修改这两个参数的值,例如将-Xmx设为2G将-X......