This is a simple tutorial for creating python wrapper for c++ code. Two simple C++ functions are wrapped and called from python code. One function takes parameter by value and reference.
This tutorial is tested on python 3.6
git clone https://github.com/ahmdtaha/pyrex_wrapper.git
cd pyrex_wrapper/
python setup.py build_ext -i
python pymain.py # python code calls c++ functions.
To create your own, here are the main steps
- Add the c function definition and implementation to a .h and .cpp file respectively-- similar to msrc.h, msrc.cpp
- Define python pyrex wrapper for the c functions in pyrex file (.pyx) -- similar to pyxtutorial.pyx. Pyrex is best described as "python with C data types". More information available in wiki and readthedocs.io
- Create setup.py to build the C++ code, generate the C++ shared library.
- Now a shared .so library is available to be imported from python code