I have a small cython module called deLorean.pyx
cdef public struct Vehicle:
int speed
float power
cdef public api void activate(int v):
print "Time travel achieved at " + str(v) + " mph."
I also have a setup.py file that looks like this:
from distutils.core import setup
from Cython.Build import cythonize
setup(name = 'First try', ext_modules = cythonize(["deLorean.pyx"]),)
When I go to compile the cython code using this: cython deLorean.pyx
This will then generate *.h, *.c, and *_api.h files.
I also have a c program called marty.c that looks like this:
#include "Python.h"
#include "deLorean_api.h"
#include <stdlib.h>
struct Vehicle car;
int main(int argc, char** agrv){
printf("HELLO");
Py_Initialize();
import_deLorean();
car.speed = 33;
car.power = 12.3;
printf("speed: %d, power: %f", car.speed, car.power);
activate(12);
Py_Finalize();
return 0;
}
I then compile the entire module using this:
gcc -fPIC -L/usr/lib -I/usr/local/include/python2.7 -lpython2.7 deLorean.c marty.c -o deLorean -g
This compiles with these notes:
/usr/bin/ld: skipping incompatible /usr/lib/libc.so when searching for -lc
/usr/bin/ld: skipping incompatible /usr/lib/libc.a when searching for -lc
This creates an a.out file; however, it seg faults when run.
When I run it in gdb, this is the output:
(gdb) r
Starting program: /root/Asta/Cython-0.22.1/deLorean
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/libthread_db.so.1".
Program received signal SIGSEGV, Segmentation fault.
0x0000000000000000 in ?? ()
(gdb)
I have played around with marty.c and I have narrowed down the culprit to when the activate() function is called. Is there something I have overlooked? What could possible be causing this behavior?