Cython帮助:跳过不兼容的库

时间:2015-07-07 21:58:14

标签: python c cython libc

我有一个名为deLorean.pyx的小型cython模块

cdef public struct Vehicle:
    int speed
    float power

cdef public api void activate(int v):
        print "Time travel achieved at " + str(v) + " mph."

我还有一个看起来像这样的setup.py文件:

from distutils.core import setup
from Cython.Build import cythonize

setup(name = 'First try', ext_modules = cythonize(["deLorean.pyx"]),)

当我使用以下代码编译cython代码时:cython deLorean.pyx

然后生成* .h,* .c和* _api.h文件。

我还有一个名为marty.c的程序,如下所示:

#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;
}

然后我用这个编译整个模块:

gcc -fPIC -L/usr/lib -I/usr/local/include/python2.7 -lpython2.7 deLorean.c marty.c -o deLorean -g

这包含以下注释:

/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

这会创建一个a.out文件;但是,它在运行时会出现故障。

当我在gdb中运行它时,这是输出:

(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)

我玩过marty.c并且在调用activate()函数时缩小了罪魁祸首。有什么我忽略了吗?有什么可能导致这种行为?

0 个答案:

没有答案