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

房东的猫 提交于 2019-12-01 22:41:53

The libpython3.so library is there to support PEP 384 -- Defining a Stable ABI.

Historically, Python has not guaranteed ABI stability at the C level between minor version releases (e.g. between 3.4 and 3.5). 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.

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. If a program or extension limited itself to only using this subset, then it could theoretically be used across different Python versions without recompilation.

Once you've compiled some code using the stable ABI, there is still the question of how to link to the runtime. For Python 3.5.x, you'd want to link using -lpython3.5m. For Python 3.6.x, you want -lpython3.6m. This is where libpython3.so comes in.

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.

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.

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!