A learning example for calling C functions from Python with ctypes.
- Write the C function in a source file.
- Declare the function in a header file.
- Compile the C source as a shared library.
- Load the shared library from Python with
ctypes.CDLL. - Call the exported function from Python.
The exact compiler command depends on the operating system and compiler. The older example in this repository uses Linux-style shared-library tooling and should be adapted rather than copied unchanged to every platform.
Tejas Dixit — https://tejasdixit.in