Minimal template for using C++ code from Python via Cython
How to compile
- Compile C++ code using CMake.
mkdir build
cd build
cmake ..
make
cd ..
- Compile and install the Python module.
cd python/
python setup.py build_ext --inplace
python setup.py install
- In a Python shell, try calling functions
example()
,run()
, andmultiply()
:
In [1]: import hello
In [2]: hello.example()
Hello, Philip Cho!
Hello, John Doe!
In [3]: hello.run()
Hello, Philip Cho!
Hello, John Doe!
In [4]: hello.multiply(2, -3)
Out[4]: -6