尝试使用cython和mingw编译hello world时出错

时间:2014-10-03 16:11:56

标签: python gcc mingw cython

我已经花了2天时间尝试了我在本网站上看到的所有内容。我试图让cython在python中编译基本的helloworld脚本,但是有错误。 Gcc似乎无法看到python头文件尽管列出的路径是正确的,我已经验证文件是否存在(例如c:/Python27/include/pyconfig.h)我已经包含了使用的文件我的设置。

helloWorld.pyx

print 'Hello World'

setup.py

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

setup(
    ext_modules = cythonize("helloWorld.pyx")
)

cmd line

python setup.py build_ext --inplace --compiler = mingw32

错误

  

编译helloworld.pyx,因为它已更改。 Cythonizing   helloworld.pyx正在运行build_ext building' helloworld'延期   C:\ MinGW \ bin \ gcc.exe -mno-cygwin -mdll -O -Wall -IC:\ Python27 \ include   -IC:\ Pytho n27 \ PC -c helloworld.c -o build \ temp.win32-2.7 \ Release \ helloworld.o在包含的文件中   helloworld.c:8:C:/Python27/include/pyconfig.h:68:16:io.h:没有这样的   文件或目录C:/Python27/include/pyconfig.h:296:20:stdio.h:没有   此类文件或目录包含在文件中   C:/ MinGW / bin /../ lib / gcc / mingw32 / 3.4.5 / include / limits.h:122,来自   C:/ MinGW / bin /../ lib / gcc / mingw32 / 3.4.5 / include / syslimits.h:7,from   C:/ MinGW / bin /../ lib / gcc / mingw32 / 3.4.5 / include / limits.h:11,from   C:/Python27/include/Python.h:19,来自helloworld.c:16:   /mingw/lib/gcc/mingw32/3.4.5/include/limits.h:122:61:limit.h:No   这样的文件或目录在helloworld.c中包含的文件:16:   C:/Python27/include/Python.h:35:5:#error" Python.h要求   stdio.h定义NULL。" C:/Python27/include/Python.h:38:20:string.h:不   这样的文件或目录C:/Python27/include/Python.h:40:19:errno.h:否   这样的文件或目录C:/Python27/include/Python.h:42:20:stdlib.h:   没有这样的文件或目录C:/Python27/include/Python.h:56:20:   assert.h:没有这样的文件或目录   C:/Python27/include/Python.h:58,来自helloworld.c:16:   C:/Python27/include/pyport.h:325:76:math.h:没有这样的文件或目录   C:/Python27/include/pyport.h:338:18:time.h:没有这样的文件或目录   C:/Python27/include/pyport.h:390:22:sys / stat.h:没有这样的文件或   目录在C:/Python27/include/Python.h:80中包含的文件中   helloworld.c:16:C:/Python27/include/object.h:307:错误:语法错误   之前" FILE" C:/Python27/include/object.h:459:错误:语法错误   之前" FILE"在C:/Python27/include/Python.h:85中包含的文件中,   来自helloworld.c:16:C:/Python27/include/unicodeobject.h:57:19:   ctype.h:没有这样的文件或目录   C:/Python27/include/unicodeobject.h:120:21:wchar.h:没有这样的文件或   目录在C:/Python27/include/Python.h:108中包含的文件中   helloworld.c:16:C:/Python27/include/fileobject.h:12:错误:语法   错误之前" FILE" C:/Python27/include/fileobject.h:12:警告:没有   结构或联合结束时的分号   C:/Python27/include/fileobject.h:15:错误:语法错误之前' '   令牌C:/Python27/include/fileobject.h:33:错误:语法错误之前   '}' token C:/Python27/include/fileobject.h:33:warning:type defaults   到int' in declaration of PyFileObject'   C:/Python27/include/fileobject.h:33:警告:数据定义没有   类型或存储类C:/Python27/include/fileobject.h:44:错误:   ' '之前的语法错误标记C:/Python27/include/fileobject.h:45:   错误:' '之前的语法错误代币   C:/Python27/include/fileobject.h:46:错误:语法错误之前' '   token C:/Python27/include/fileobject.h:46:warning:type defaults to   int' in declaration of PyFile_AsFile' C:/Python27/include/fileobject.h:46: warning: data definition has no type or storage class C:/Python27/include/fileobject.h:47: error: syntax error before '*' token C:/Python27/include/fileobject.h:48: error: syntax error before '*' token C:/Python27/include/fileobject.h:65: error: syntax error before "FILE" C:/Python27/include/fileobject.h:66: error: syntax error before "FILE" In file included from C:/Python27/include/Python.h:127, from helloworld.c:16: C:/Python27/include/pythonrun.h:35: error: syntax error before '*' token C:/Python27/include/pythonrun.h:36: error: syntax error before '*' token C:/Python27/include/pythonrun.h:38: error: syntax error before '*' token C:/Python27/include/pythonrun.h:39: error: syntax error before '*' token C:/Python27/include/pythonrun.h:40: error: syntax error before '*' token C:/Python27/include/pythonrun.h:45: error: syntax error before '*' token C:/Python27/include/pythonrun.h:55: error: syntax error before '*' token C:/Python27/include/pythonrun.h:61: error: syntax error before '*' token C:/Python27/include/pythonrun.h:78: error: syntax error before '*' token C:/Python27/include/pythonrun.h:152: error: syntax error before '*' token C:/Python27/include/pythonrun.h:154: error: syntax error before '*' token In file included from C:/Python27/include/Python.h:129, from helloworld.c:16: C:/Python27/include/sysmodule.h:12: error: syntax error before '*' token C:/Python27/include/sysmodule.h:12: error: syntax error before "FILE" C:/Python27/include/sysmodule.h:12: warning: type defaults to INT'在声明PySys_GetFile' C:/Python27/include/sysmodule.h:12: warning: data definition has no type or storage class In file included from C:/Python27/include/Python.h:131, from helloworld.c:16: C:/Python27/include/import.h:39: error: syntax error before "FILE" helloworld.c: In function __ PYX_NAN':helloworld.c:315:警告:   隐式声明函数memset' helloworld.c: In function __ Pyx_PyUnicode_FromString':helloworld.c:1423:警告:隐式   函数声明strlen' helloworld.c: In function __ Pyx_PyObject_AsStringAndSize':helloworld.c:1474:警告:隐式   函数声明`断言'错误:命令   ' C:\ MinGW的\ BIN \ gcc.exe'退出状态1失败

1 个答案:

答案 0 :(得分:1)

正如IanH评论的那样,看起来GCC未能找到Python头中包含的标准C头,而不是Cython的问题。你能编译一个简单的C程序,如下所示:

#include <stdio.h>
int main(void)
{
  printf("Hello World\n");
  return 0;
}

编译:

$ gcc hello.c -o hello.exe

相关问题