井民全, Jing, mqjing@gmail.com
File: my_python.pyx
------------------------------------------------
# cython syntax
cdef public void my_python_module():
print('1234')
my_python_module()
# python syntax
def my_python_module():
print('1234')
------------------------------------------------
File: main.c
------------------------------------------------
#include
#include "my_python.h"
int main() {
Py_Initialize();
PyInit_my_python(); // init the python module
my_python_module(); // call my python module
Py_Finalize();
return 0;
}
------------------------------------------------
Build
cython -3 my_python.pyx
gcc my_python.c -o my_python.o -shared -pthread -fPIC -fwrapv -O2 -Wall -fno-strict-aliasing -I/usr/include/python3.5
gcc main.c -o main.o -ldl my_python.o -I/usr/include/python3.5 -L/usr/lib/python3.5/config-3.5m-x86_64-linux-gnu -lpython3.5