MacOS Big Sur - Python ctypes find_library 找不到库(ssl、CoreFoundation 等)

Ter*_*nal 11 python macos ctypes

MacOS Big Sur 已发布开发测试版,我正在运行它以测试一些内容。我注意到的一件事是,在 Python ctypes 中,find_library()不再找到库。

一个例子是

from ctypes.util import find_library

find_library("ssl")
Run Code Online (Sandbox Code Playgroud)

这应该找到ssl类似于输出的文件

>>> find_library("ssl")
'libssl.so.1.1'
Run Code Online (Sandbox Code Playgroud)

但是,对于 Big Sur,它什么也没找到。我注意到他们有一些动态链接器的变化。这可能会导致这种行为。

有人遇到过这种情况么?我正在寻找在 Big Sur 系统中查找库的新方法。

我相信它与 iOS 相同,因为它/System/Library/dyld/dyld_shared_cache_x86_64用于共享缓存。但我不够熟悉,不知道如何打开该文件以访问 CoreFoundations、ssl 等内容。仍在研究它。

小智 6

此问题是由于 pythonstat()在 dlopen 之前检查磁盘上的 dylib。此行为在 macOS Big Sur 中停止工作,因为当 dylib 包含在 dyld 共享缓存中时,它们被从磁盘中删除。

macOS 中包含的 python 对此进行了修复。

/usr/bin/python3
from ctypes.util import find_library
>>> find_library("ssl")
'libssl.so.1.1'
Run Code Online (Sandbox Code Playgroud)

此外,这里还有一个链接,指向开源 python 的拉取请求,以进行相同的修复。 https://github.com/python/cpython/pull/21241


Ter*_*nal 0

我最终使用静态路径来达到我的目的。