Python如何加载C++共享库

发布于 2025-01-26 09:09:25 字数 446 浏览 4 评论 0原文

上下文:我有一个Python程序,该程序依赖于通过Pybinder暴露的C ++中实现的多个库。 我的印象是:当Python 导入XXX时,它将共享库(.so)加载到虚拟内存中。这是我记得我从书或网页中读到的东西,但现在找不到。

我想知道如何在Linux中验证它?我尝试使用event open ,唯一打开的共享库是py/__ init __。对我来说看起来不正确。

在代码库中,我有多个具有多个版本的Libcurl,所有版本均由3-RD PAIRNE库介绍。我想知道我在运行Python应用程序时是否有办法执行,它们不干预?

例如:Python程序A依赖于C ++共享库B和C。 B依赖于Libcurl(V1),静态链接。 C还依赖于libcurl(V2),也静态链接。 如果B调用Libcurl(V2),可能会发生坏事,因为可能发生冲突。

context: I have a python program which relies on multiple libraries implemented in C++, exposed via pybinder.
My impression is: when python import xxx, it loads shared libraries (.so) into virtual memory. This is something I remember I read from book or webpage but cannot find it now.

I want to know how I can verify it in Linux? I tried to strace with event open, the only shared libraries opened are something like py/__init__.so (all python internal libraries), which doesn't look correct to me.

In the code base, I have multiple libcurl with multiple versions, all of them are introduced by 3-rd parties libraries. I want to know if I have a way to enforce when running python applications, they don't intervene?

For example: python program A relies on C++ shared library B and C.
B relies on libcurl (V1), statically linked.
C also relies on libcurl (V2), also statically linked.
Bad things could happen if B invokes libcurl (V2), since there might be conflict.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

临走之时 2025-02-02 09:09:25

在Linux系统上,您可以通过运行cat/proc/pid/maps pid> pid 是相关的过程ID,从而将哪些动态库加载到过程中。

关于您的第二个问题:如果库在静态上链接到libcurl,那么他们将无法使用错误的库版本:链接是静态的。

如果链接是动态的,则只能加载一个libcurl。但是,libcurl似乎是相对较高的API/ABI稳定,因此这通常不是问题。

On Linux systems, you can see which dynamic libraries are loaded into a process by running cat /proc/pid/maps where pid is the relevant process ID.

About your second question: If the libraries are statically linked to libcurl then they cannot use the wrong library version: the linking is static.

If the linking is dynamic then only one libcurl can be loaded. However libcurl seems to be relatively API/ABI stable so this usually wouldn't be a problem.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文