How to use Cython functions in C/C++ and Python within the same project?

Viewed 113

I've been learning about Cython recently. I'm still a beginner, but I'm excited about the prospect of using it in the future.

In my mind, Cython has two main uses:

  1. Making Cython or C/C++ functions accessible from Python. See: Calling C functions.

    • You can expose Cython and C/C++ functions to Python by making a Cython module extension using setuptools.
  2. Making Cython or Python functions accessible from C/C++. See: Embedding Cython modules in C/C++ applications.

    • You can expose Cython and Python functions to C/C++ by embedding the Python interpreter into your C/C++ application using Py_Initialize and company.

What if you want to do both of these things for the same project?

Is there a way to use Cython to create a shared object (.so) file which can both be imported as a Python module, and linked against from C/C++?

0 Answers
Related