Building a ctypes-“based” C library with distutils

后端 未结 3 443
南旧
南旧 2020-12-29 03:45

Following this recommendation, I have written a native C extension library to optimise part of a Python module via ctypes. I chose ctypes over writing a CPython-native libra

3条回答
  •  情话喂你
    2020-12-29 04:39

    I have setup a minimal working python package with ctypes extension here: https://github.com/himbeles/ctypes-example which works on Windows, Mac, Linux.

    • It takes the approach of memeplex above of overwriting build_ext.get_export_symbols() and forcing the library extension to be the same (.so) for all operating systems.
    • Additionally, a compiler directive in the c / c++ source code ensures proper export of the shared library symbols in case of Windows vs. Unix.
    • As a bonus, the binary wheels are automatically compiled by a GitHub Action for all operating systems :-)

提交回复
热议问题