python使用ctypes调用第三方库时出现undefined symbol错误详解

python中时间的库有time和datetime,pandas也有提供相应的时间处理函数,下面这篇文章主要给大家介绍了关于python使用ctypes调用第三方库时出现undefined symbol错误的相关资料,需要的朋友可以参考下

今天在用python 调用c++库文件时出现了一个错误,这里主要记录一下解决问题的思路。

1.出现错误

在使用python 中使用中调用第三方so库时

import ctypes cpp = ctypes.CDLL('./detector.so') 

出现如下错误:

Traceback (most recent call last):
File “detection.py”, line 143, in
face_detection(image_path)
File “detection.py”, line 52, in face_detection
cpp = ctypes.CDLL(’./detector.so’)
File “/usr/lib/python3.8/ctypes/init.py”, line 373, in init
self._handle = _dlopen(self._name, mode)
OSError: ./detector.so: undefined symbol: __powf_finite

这是由于未定义__powf_finite引起的。

2.分析步骤

(1)使用file命令检查so库的架构,看是否平台一致

file detector.so

输出:

detector.so: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, BuildID[sha1]=8ac2d2c5490394447e21cf383f1428d8ad70be7a, with debug_info, not stripped

发现平台是没有问题的。

(2)使用 ldd -r xxx.so 查看so库链接状态和错误信息

ldd -r detector.so

输出如下:

确实存在 undefined symbol: __powf_finite (./detector.so) 等问题,

(3)使用c++filt 定位错误位置

使用以下命令来查找在c++代码中的位置

c++filt __powf_finite

最后面发现是我c++代码的问题,我在c++代码中又引用了第三方库.a文件,是.a文件的问题,这个文件是以前的老代码生成的,自己重新编译源码生成新的 .a文件就可以解决了。

总结

到此这篇关于python使用ctypes调用第三方库时出现undefined symbol错误的文章就介绍到这了,更多相关python ctypes调用undefined symbol内容请搜索0133技术站以前的文章或继续浏览下面的相关文章希望大家以后多多支持0133技术站!

以上就是python使用ctypes调用第三方库时出现undefined symbol错误详解的详细内容,更多请关注0133技术站其它相关文章!

赞(0) 打赏
未经允许不得转载:0133技术站首页 » python