简体   繁体   English

与从python 3.5.2源构建的libpython3.5m.so相比,libpython3.so是什么?

[英]What is libpython3.so compared with libpython3.5m.so built from python 3.5.2 source?

In my application, I use boost_python and python 3.5.2. 在我的应用程序中,我使用boost_python和python 3.5.2。 All built from source in Ubuntu 14. 全部由Ubuntu 14。

When I built Python 3.5.2 from source with --with-shared options in Ubuntu, I got libpython3.so (7.6kB) and libpython3.5m.so (12MB). 当我在Ubuntu中使用--with-shared选项从源代码构建Python 3.5.2时,我得到了libpython3.so (7.6kB)和libpython3.5m.so (12MB)。 I assume the big one is the real one and the small one might be something forwarding calls to the real interfaces. 我认为大的是真实的,小的可能是将呼叫转发到真实接口的东西。

As boost_python might assume the client to link against python ( https://svn.boost.org/trac/boost/ticket/2615 ), I linked libpython3.so with my application. 由于boost_python可能假设客户端要链接到python( https://svn.boost.org/trac/boost/ticket/2615 ),所以我将libpython3.so与我的应用程序链接了。 But when I run it, I got the unresolved symbols error. 但是,当我运行它时,出现了无法解析的符号错误。

ldd -r myapp or ldd -r libboost_python.so both listed all python symbols unresolved which could be found in nm -D libpython3.5m.so . ldd -r myappldd -r libboost_python.so都列出了所有未解析的python符号,这些符号可以在nm -D libpython3.5m.so找到。

# ldd -r lib/libboost_python3.so
    linux-vdso.so.1 => (0x00007ffe767fb000)
    libstdc+.so.6 => /usr/lib/x86_64-linux-gnu/libstdc+.so.6 (0x00007f130a7a3000)
    libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f130a58d000)
    libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f130a1c8000)
    libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f1309ec2000)
    /lib64/ld-linux-x86-64.so.2 (0x00007f130acf4000)
undefined symbol: PyExc_ImportError (lib/libboost_python3.so)
undefined symbol: PyProperty_Type (lib/libboost_python3.so)
undefined symbol: PyExc_StopIteration (lib/libboost_python3.so)
undefined symbol: PyBool_Type (lib/libboost_python3.so)
undefined symbol: PyExc_ValueError (lib/libboost_python3.so)
undefined symbol: PyList_Type (lib/libboost_python3.so)
undefined symbol: _Py_NotImplementedStruct (lib/libboost_python3.so)
undefined symbol: PyExc_TypeError (lib/libboost_python3.so)
undefined symbol: PyDict_Type (lib/libboost_python3.so)
...

libpython3.so depend on libpython3.5m.so but itself has no those symbols. libpython3.so依赖于libpython3.5m.so但本身没有这些符号。

I think based on that I should link my application with libpython3.5m.so instead of with libpython3.so . 我认为基于此,我应该将我的应用程序与libpython3.5m.so链接,而不是与libpython3.so But the weird thing is that if I use LD_PRELOAD to load the libpython3.so, those symbols are found in ldd -r libboost_python3.so 但是很奇怪的是,如果我使用LD_PRELOAD加载libpython3.so,那么这些符号可以在ldd -r libboost_python3.so中找到

# LD_LIBRARY_PATH=lib LD_PRELOAD=lib/libpython3.so ldd -r lib/libboost_python3.so
    linux-vdso.so.1 => (0x00007ffcb51f0000)
    lib/libpython3.so (0x00007f6f728e3000)
    libstdc+.so.6 => /usr/lib/x86_64-linux-gnu/libstdc+.so.6     (0x00007f6f725df000)
    libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f6f723c9000)
    libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f6f72004000)
    libpython3.5m.so.1.0 => lib/libpython3.5m.so.1.0 (0x00007f6f71ae1000)
    libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0     (0x00007f6f718c3000)
    libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f6f715bd000)
    /lib64/ld-linux-x86-64.so.2 (0x00007f6f72d32000)
    libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f6f713b9000)
    libutil.so.1 => /lib/x86_64-linux-gnu/libutil.so.1 (0x00007f6f711b6000)

Why having the libpython3.so and how to use it? 为什么要拥有libpython3.so以及如何使用它? Or shall I just only use the libpython3.5m.so directly? 还是只直接使用libpython3.5m.so

The libpython3.so library is there to support PEP 384 -- Defining a Stable ABI . libpython3.so库在那里支持PEP 384-定义稳定的ABI

Historically, Python has not guaranteed ABI stability at the C level between minor version releases (eg between 3.4 and 3.5). 从历史上看,Python不能保证次要版本之间(例如3.4和3.5之间)的C级ABI稳定性。 They might be source compatible but certain structures might change size, or structure members change type, etc. However, there are portions of the ABI that are mature and have remained stable over a longer period. 它们可能是源兼容的,但是某些结构可能会更改大小,或者结构成员会更改类型等。但是,ABI的某些部分已经成熟并且可以在更长的时间内保持稳定。

The Stable ABI PEP identified a subset of the Python C API that was stable wouldn't place undue restrictions on future Python development if the developers committed to maintaining binary compatibility for the subset. 稳定的ABI PEP确定了Python C API的一个子集,如果开发人员致力于维护该子集的二进制兼容性,那么该子集不会对未来的Python开发施加不适当的限制。 If a program or extension limited itself to only using this subset, then it could theoretically be used across different Python versions without recompilation. 如果程序或扩展将自身限制为仅使用此子集,则理论上可以在不重新编译的情况下跨不同的Python版本使用它。

Once you've compiled some code using the stable ABI, there is still the question of how to link to the runtime. 使用稳定的ABI编译一些代码后,仍然存在如何链接到运行时的问题。 For Python 3.5.x, you'd want to link using -lpython3.5m . 对于Python 3.5.x,您需要使用-lpython3.5m进行链接。 For Python 3.6.x, you want -lpython3.6m . 对于Python 3.6.x,您需要-lpython3.6m This is where libpython3.so comes in. 这是libpython3.so进入的地方。

The libpython3.so library only has one purpose: for Python 3.5 it links to libpython3.5m.so , and on 3.6 it links to libpython3.6m.so , etc. So if an extension links using -lpython3 , it will have access to the runtime of the version of Python installed on the system. libpython3.so库仅具有一个用途:对于Python 3.5,它链接到libpython3.5m.so ,在3.6上它链接到libpython3.6m.so等。因此,如果扩展使用-lpython3链接,它将可以访问系统上安装的Python版本的运行时。

Now back to your original problem: unless you are absolutely sure that you are only using features found in the stable ABI (which in your case means finding out whether libboost_python only uses the stable ABI), then you probably want to link to the versioned libpython3.5m.so . 现在回到您的原始问题:除非您完全确定只使用稳定ABI中的功能(在您的情况下,这意味着确定libboost_python是否仅使用稳定ABI),那么您可能想要链接到版本化的libpython3.5m.so

If in doubt, you're better off linking to the versioned library: it is much easier to debug a dynamic link error than a segfault due to ABI changes, should you upgrade to a newer version of Python. 如有疑问,最好链接到版本库:调试动态链接错误比由于ABI更改而引起的段错误要容易得多,如果您升级到更新版本的Python。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从AIX5.3上的Source构建的Python 2.7无法为libpython2.7.so执行 - Python 2.7 built from Source on AIX5.3 does not execute for libpython2.7.so Python3.5 导入错误:libpython3.5m.so.1.0:无法打开共享对象文件:没有这样的文件或目录 - Python3.5 ImportError: libpython3.5m.so.1.0: cannot open shared object file: No such file or directory pyinstaller 错误:OSError:找不到 Python 库:libpython3.4mu.so.1.0、libpython3.4m.so.1.0、libpython3.4.so.1.0 - pyinstaller error: OSError: Python library not found: libpython3.4mu.so.1.0, libpython3.4m.so.1.0, libpython3.4.so.1.0 OSError: Python library not found: libpython3.9mu.so.1.0, libpython3.9m.so, etc., when running pyinstaller - OSError: Python library not found: libpython3.9mu.so.1.0, libpython3.9m.so, etc., when running pyinstaller 加载共享库时出现 Python 错误:libpython3.5m.so.1.0:无法打开共享对象文件:没有这样的文件或目录 - Python error while loading shared libraries: libpython3.5m.so.1.0: cannot open shared object file: No such file or directory Anaconda Python virtualdev在Windows的Linux子系统上找不到libpython3.5m.so.1.0(Ubuntu 14.04) - Anaconda Python virtualdev can't find libpython3.5m.so.1.0 on Windows Subsystem for Linux (Ubuntu 14.04) Pyinstaller:无法打开共享对象 libpython3.5m.so.1.0 - Pyinstaller: Cannot open shared object libpython3.5m.so.1.0 错误加载 Python 库 libpython3.6m.so.1.0 pyinstaller Ubuntu Python - Error loading Python lib libpython3.6m.so.1.0 pyinstaller Ubuntu Python Azure Function Python 导入错误:libpython3.6m.so.1.0 - Azure Function Python Import Error : libpython3.6m.so.1.0 Python3.7:加载共享库时出错:libpython3.7m.so.1.0 - Python3.7: error while loading shared libraries: libpython3.7m.so.1.0
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM