4. 建立 C 與 C++ 擴充套件¶
一個 CPython 的 C 擴充套件是一個共用函式庫(例如在 Linux 上的 .so
檔案,在 Windows 上的 .pyd
),會匯出一個初始化函式。
詳見 Defining extension modules。
4.1. 用 setuptools 建置 C 與 C++ 擴充套件¶
Building, packaging and distributing extension modules is best done with third-party tools, and is out of scope of this document. One suitable tool is Setuptools, whose documentation can be found at https://setuptools.pypa.io/en/latest/setuptools.html.
直到 Python 3.12 版本前,distutils
模組都被包含在標準函式庫中,現在是作為 Setuptools 的一部分來維護。