Trying to harness the feature of public functions and classes in cython I immediately ran into a problem with simplest things. Two days of googling and reading the forums yielded no result. Documentation says kinda: "just use it, and it will work". Ok.
public.pxd:
# cython: language_level=3
public.pyx:
cdef public void Qu():
print("Qu!")
public_c.c:
#include <Python.h>
#include "public.h"
int main() {
Py_Initialize();
PyInit_public();
printf("Init\n");
Qu();
printf("Finalize\n");
Py_Finalize();
}
compile.sh:
#!/bin/bash
cython public.pyx
gcc -fPIC $(python3-config --cflags) -c public.c -o public.o
gcc -fPIC $(python3-config --cflags) -c public_c.c -o public_c.o
gcc public_c.o public.o $(python3-config --ldflags) -lpython3.9 -o public_c
No errors or warnings during compilation. Cython generated .c and .h files look ok. But...
$ ./public_c
Init
Segmentation fault
Even this simplest try fails. What am I doing wrong?