I have a cython
file random.pyx
like this:
cdef public int get_random_number():
return 4
with setup.py
like this:
from distutils.core import setup
from Cython.Build import cythonize
from distutils.extension import Extension
extensions = [Extension("librandom", ["random.pyx"])]
setup(
ext_modules = cythonize(extensions)
)
Then I get a dynamic library librandom.so
, now I want to use this so
file in c++ instead of python.
#include <stdio.h>
#include "random.h"
int main() {
printf("%d\n",get_random_number());
return 0;
}
now I get error like this when I compile g++ -o main main.cpp -lrandom -L. -Wl,-rpath,"\$ORIGIN"
:
In file included from main.cpp:2:0:
random.h:26:1: error: ‘PyMODINIT_FUNC’ does not name a type
PyMODINIT_FUNC initrandom(void);