View on GitHub

CandPythonBridge

This Repo contains all info about how to call the c function in python.

CandPythonBridge

A learning example for calling C functions from Python with ctypes.

Basic workflow

  1. Write the C function in a source file.
  2. Declare the function in a header file.
  3. Compile the C source as a shared library.
  4. Load the shared library from Python with ctypes.CDLL.
  5. 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.

Author

Tejas Dixit — https://tejasdixit.in