binary using both Python C API version 2 and 3

混江龙づ霸主 提交于 2021-02-05 08:28:06

问题


In an open source project1 we have Python/Cython and C/C++ modules mixed with one C++ library using the Python C API. The API changed only a few function's names from 2 to 3. Assume the library is written without those functions. Will it link to Python3 if compiled with Python2, and vice versa? Is this prevented by macros in the API headers?

Having a library binary that may link to both would spare us major packaging hassles.


回答1:


No, it wouldn't work. Don't try it.

Binary modules are not guaranteed to be binary-portable even say from 3.5 to 3.6. If you're lucky, then there is some mechanism that will prohibit you from doing this insanity. If however you manage to link the library somehow, there will be some subtle differences that will cause serious bugs, such as the layout of PyObject changing and so forth.

The Python interface must be recompiled for the exact Python version. Source compatibility between Python 2 and 3 is a different thing and is relatively easy to achieve.



来源:https://stackoverflow.com/questions/44322187/binary-using-both-python-c-api-version-2-and-3

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