相关疑难解决方法(0)

如何使用gcc从Cython编译.c代码

现在我已经在Windows 7上成功安装了Cython,我尝试使用Cython编译一些Cython代码,但是gcc让我的生活变得艰难.

cdef void say_hello(name):
    print "Hello %s" % name
Run Code Online (Sandbox Code Playgroud)

使用gcc编译代码会引发许多未定义的 -erros 引用,我很确定它libpython.a是可用的(正如安装教程所说,如果缺少此文件,则会引发未定义的引用错误).

$ cython ctest.pyx
$ gcc ctest.c -I"C:\Python27\include"
Run Code Online (Sandbox Code Playgroud)

C:\Users\niklas\AppData\Local\Temp\cckThGrF.o:ctest.c:(.text+0x1038): undefined reference to `_imp__PyString_FromStringAndSize'
C:\Users\niklas\AppData\Local\Temp\cckThGrF.o:ctest.c:(.text+0x1075): undefined reference to `_imp___Py_TrueStruct'
C:\Users\niklas\AppData\Local\Temp\cckThGrF.o:ctest.c:(.text+0x1086): undefined reference to `_imp___Py_ZeroStruct'
C:\Users\niklas\AppData\Local\Temp\cckThGrF.o:ctest.c:(.text+0x1099): undefined reference to `_imp___Py_NoneStruct'
C:\Users\niklas\AppData\Local\Temp\cckThGrF.o:ctest.c:(.text+0x10b8): undefined reference to `_imp__PyObject_IsTrue'
c:/program files/mingw/bin/../lib/gcc/mingw32/4.5.2/../../../libmingw32.a(main.o):main.c:(.text+0xd2): undefined reference to `WinMain@16'
collect2: ld returned 1 exit status
Run Code Online (Sandbox Code Playgroud)

奇怪的是,使用pyximport*或setup-script工作得非常好,但是当它仍在处理模块时它们都不是很方便.

如何.c使用gcc 编译使用Cython生成的文件?

或任何其他编译器,重要的是它会工作!


*pyximport:在导入的模块中只包含python-native函数和类而不包含cdef函数和类,这是正常的吗?喜欢:

# filename: cython_test.pyx
cdef c_foo(): …
Run Code Online (Sandbox Code Playgroud)

c python gcc compilation cython

20
推荐指数
1
解决办法
2万
查看次数

标签 统计

c ×1

compilation ×1

cython ×1

gcc ×1

python ×1