Dynamic linking
If you want to link dynamically, use as the followings on extension()
libraries=[“m”]
Let’s another exmples.
If you want access C code for which Cython does not porvide a ready to use declaration, you must declare them yourself.
Just define like this :
This declares the sin() function in a way that makes it available to Cython code and instructs Cython to generate C code that includes the math.h header file.
The C compiler will see the original declaration in math.h at compile time, but Cython does not parse “math.h” and requires a separate definition.
Just like the sin() function from the math library, it is possible to declare and call into any C library as long as the module that Cython generates is properly linked against the shared and static library.
OR
Note taht you can easily export an external C function from your Cython module by declaring it as cpdef.
This generates a Python wrapper for it and adds it to the module dict.
The following is a Cython module that provides direct access to the C cos() function for python code :
Also you would get the same result when This declaration appears in the .pxd file that belong to the Cython moduleand This allows the C declaration to be resued in other Cython modules.
Let’s import things above like this: