Compiling cython code
=====================

cython
------

* If you only have C code in your cython code (no exceptions, no std containers, no classes), run

$ cython <name>.pyx

* If you have C++ code in your cython code, run

$ cython -+ <name>.pyx

since the argument -+ tells cython that this is actually C++ containing code. With the argument -+ the output file from cython is called <name>.cpp and not <name>.c, therefore you have to be careful in naming your .pxy-file, i.e. it should not have the same name as an already existing .cpp file containing e.g. the implementation of a C++ class.



compiling the resulting C/C++ code
----------------------------------

* MacOS X:

$ gcc -O2 -fPIC -I<path_to_python_include_file> -c <name>.c -o <name>.o

$ gcc -bundle -undefined dynamic_lookup -L<path_to_python_library> -lpython3.5 <name>.o -o <name>.so


* Debian (Linux)

$ gcc -O2 -fPIC -I<path_to_python_include_file> -c <name>.c -o <name>.o

$ gcc -shared -L<path_to_python_library> -lpython3.5 <name>.o -o <name>.so

For the laptops used in the course:
<path_to_python_include_file> = /usr/include/python3.5
<path_to_python_library> = /usr/lib

* C++ code

Compiling cython code based on C++ code with the commands shown above might cause some problems. In this case replace the compiler (i.e. gcc -> g++, clang -> clang++). And you might need to add for the second step (i.e. the linking creating the .so file) the argument -lstdc++ by hand (sometimes it is implicitly added by g++/clang++)


