我有一个qt应用程序,我希望在其中实现python解释器,这样我就可以用python脚本扩展它。虽然这对于常规的C++应用程序(包括Python.h )很好,但即使对于大多数简单、空的Qt4项目,也总是会产生如下结果:
g++ -c -m64 -pipe -O2 -Wall -W -D_REENTRANT -DQT_WEBKIT -DQT_NO_DEBUG -DQT_CORE_LIB -DQT_SHARED -I/usr/share/qt4/mkspecs/linux-g++-64 -I. -I/usr/include/qt4/QtCore -I/usr/include/qt4 -I/usr/include/python3.2mu -I. -o main.o main.cpp
In file included from /usr/include/python3.2mu/Python.h:8:0,
from main.cpp:16:
/usr/include/python3.2mu/pyconfig.h:1182:0: warning: "_POSIX_C_SOURCE" redefined [enabled by default]
/usr/include/features.h:164:0: note: this is the location of the previous definition
/usr/include/python3.2mu/pyconfig.h:1204:0: warning: "_XOPEN_SOURCE" redefined [enabled by default]
/usr/include/features.h:166:0: note: this is the location of the previous definition
In file included from /usr/include/python3.2mu/Python.h:67:0,
from main.cpp:16:
/usr/include/python3.2mu/object.h:402:23: error: expected unqualified-id before ‘;’ token
make: *** [main.o] Error 1
我只在我的.pro文件中实现了这一点:
INCLUDEPATH += "/usr/include/python3.2“
现在,当我做的时候
#include <Python.h>
在任何.h文件中,它都使其不可构建。为什么会这样呢?
注意:所有这些都与python2.7完美地工作在一起,只是python3x不能运行
编辑:我明白了,当我将Python.h作为第一个文件时,在Qt包含之前,它是否是python中的一个bug?他们是不是漏掉了安全警卫?
发布于 2013-11-30 05:08:16
Python的文档声明:
注意到可能会定义一些影响某些系统上标准头的预处理定义,所以在包含任何标准头之前,您必须包括Python.h。
很可能有些Qt标头包含标准标头(从您得到的错误中可以看出,它确实包括/usr/include/features.h
或示例),因此#include <Python.h>
应该放在Qt头之前。事实上,它通常应该放在任何其他包含-陈述之前。
请注意,Python2.7也是如此。如果一个不同的包含订单适用于Python2.7,那么您就是幸运的。
https://stackoverflow.com/questions/20300201
复制