用C程序编译python.h时出错
我正在使用Eclipse和Cygwin的GCC编译器。想在我的C程序中使用Python.h,但在编译时遇到了这些错误。有没有什么建议?
In file included from C:/Python27/include/python.h:86,
from ../src/EmbeddedPython.c:13:
C:/Python27/include/intobject.h:45: error: parse error before "PyInt_AsUnsignedLongLongMask"
C:/Python27/include/intobject.h:45: warning: type defaults to `int' in declaration of `PyInt_AsUnsignedLongLongMask'
C:/Python27/include/intobject.h:45: warning: data definition has no type or storage class
In file included from C:/Python27/include/python.h:88,
from ../src/EmbeddedPython.c:13:
C:/Python27/include/longobject.h:49: warning: parameter names (without types) in function declaration
C:/Python27/include/longobject.h:51: error: parse error before "PyLong_AsLongLong"
C:/Python27/include/longobject.h:51: warning: type defaults to `int' in declaration of `PyLong_AsLongLong'
C:/Python27/include/longobject.h:51: warning: data definition has no type or storage class
C:/Python27/include/longobject.h:52: error: parse error before "PyLong_AsUnsignedLongLong"
C:/Python27/include/longobject.h:52: warning: type defaults to `int' in declaration of `PyLong_AsUnsignedLongLong'
C:/Python27/include/longobject.h:52: warning: data definition has no type or storage class
C:/Python27/include/longobject.h:53: error: parse error before "PyLong_AsUnsignedLongLongMask"
C:/Python27/include/longobject.h:53: warning: type defaults to `int' in declaration of `PyLong_AsUnsignedLongLongMask'
C:/Python27/include/longobject.h:53: warning: data definition has no type or storage class
C:/Python27/include/longobject.h:54: error: parse error before "PyLong_AsLongLongAndOverflow"
C:/Python27/include/longobject.h:54: warning: type defaults to `int' in declaration of `PyLong_AsLongLongAndOverflow'
C:/Python27/include/longobject.h:54: warning: data definition has no type or storage class
make: *** [src/EmbeddedPython.o] Error 1
1 个回答
2
我不知道这对你有没有帮助,但在OS X上用gcc编译一个包含Python的C程序时,我需要链接到Python库。比如我在命令行中编译时用了:
gcc python_test.c -lpython2.7 -o python_test
这里的-l是一个标志,而python2.7是我的Python库文件夹。