PRECOMPILED HEADERS不工作在调试生成与Qt Creator / qmake / MinGw [英] PRECOMPILED HEADERS not working in debug build with Qt Creator / qmake / MinGw
问题描述
在Qt Creator中,我有一个使用PRECOMPILED HEADERS的pro文件。
In Qt Creator, I have a pro file using PRECOMPILED HEADERS.
当我在Release模式下构建时,构建工作非常完美。但是在调试模式下构建错误,生成目标文件失败。示例:
The build works just perfect when I build in Release mode. But building in Debug mode gives errors, generating object files failing. Example:
17:12:40: Running steps for project Euclide...
17:12:40: Configuration unchanged, skipping qmake step.
17:12:40: Starting: "C:\Qt\Tools\mingw48_32\bin\mingw32-make.exe"
C:\Qt\5.2.0\mingw48_32\bin\qmake.exe -spec win32-g++ CONFIG+=debug -o Makefile ..\euclide\Euclide.pro
C:/Qt/Tools/mingw48_32/bin/mingw32-make -f Makefile.Debug
mingw32-make[1]: Entering directory 'C:/UserPrograms/Euclide/build'
g++ -c -include debug\_pch.h -pipe -fno-keep-inline-dllexport -std=gnu++11 -g -frtti -Wall -Wextra -fexceptions -mthreads -DUNICODE -DQT_WEBKITWIDGETS_LIB -DQT_MULTIMEDIAWIDGETS_LIB -DQT_QUICK_LIB -DQT_POSITIONING_LIB -DQT_OPENGL_LIB -DQT_PRINTSUPPORT_LIB -DQT_WEBKIT_LIB -DQT_MULTIMEDIA_LIB -DQT_QML_LIB -DQT_WIDGETS_LIB -DQT_NETWORK_LIB -DQT_SENSORS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -DQT_NEEDS_QMAIN -I..\euclide -I"..\..\..\Program Files (x86)\boost\boost_1_53_0" -I"..\numlib\mathvec" -I"..\..\..\Qt\5.2.0\mingw48_32\include" -I"..\..\..\Qt\5.2.0\mingw48_32\include\QtWebKitWidgets" -I"..\..\..\Qt\5.2.0\mingw48_32\include\QtMultimediaWidgets" -I"..\..\..\Qt\5.2.0\mingw48_32\include\QtQuick" -I"..\..\..\Qt\5.2.0\mingw48_32\include\QtPositioning" -I"..\..\..\Qt\5.2.0\mingw48_32\include\QtOpenGL" -I"..\..\..\Qt\5.2.0\mingw48_32\include\QtPrintSupport" -I"..\..\..\Qt\5.2.0\mingw48_32\include\QtWebKit" -I"..\..\..\Qt\5.2.0\mingw48_32\include\QtMultimedia" -I"..\..\..\Qt\5.2.0\mingw48_32\include\QtQml" -I"..\..\..\Qt\5.2.0\mingw48_32\include\QtWidgets" -I"..\..\..\Qt\5.2.0\mingw48_32\include\QtNetwork" -I"..\..\..\Qt\5.2.0\mingw48_32\include\QtSensors" -I"..\..\..\Qt\5.2.0\mingw48_32\include\QtGui" -I"..\..\..\Qt\5.2.0\mingw48_32\include\QtCore" -I"debug" -I"." -I"." -I"..\..\..\Qt\5.2.0\mingw48_32\mkspecs\win32-g++" -o debug\main.o ..\euclide\main.cpp
Makefile.Debug:1543: recipe for target 'debug/main.o' failed
mingw32-make[1]: *** [debug/main.o] Error 1
mingw32-make[1]: Leaving directory 'C:/UserPrograms/Euclide/build'
makefile:34: recipe for target 'debug' failed
mingw32-make: *** [debug] Error 2
17:12:59: The process "C:\Qt\Tools\mingw48_32\bin\mingw32-make.exe" exited with code 2.
Error while building/deploying project Euclide (kit: Desktop Qt 5.2.0 MinGW 32bit)
When executing step 'Make'
17:12:59: Elapsed time: 00:19.
真正令人困惑的是,它在Release中正常工作。我用一个小项目做了一些测试,它在发布或调试模式下正常工作,但是出于任何原因,一个更大的项目失败。甚至不可能在Debug中编译项目的单个文件。
pro文件如下:
What is really confusing is that it works fine in Release. I made some tests with a small project and it works fine in Release or Debug modes, but for any reason, a bigger project is failing. It is even impossible to compile a single file of the project in Debug. The pro file is below:
QT += core gui \
webkitwidgets \
printsupport
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = Euclide
TEMPLATE = app
QMAKE_CXXFLAGS += -std=gnu++11
CONFIG += precompile_header
# Use Precompiled headers (PCH)
PRECOMPILED_HEADER = _pch.h
SOURCES += main.cpp\
mainwindow.cpp \
zero.cpp \
... lot of files here...
debug_tool.cpp
HEADERS += mainwindow.h \
zero.h \
... lot of files here...
debug_tool.h \
_pch.h
FORMS += mainwindow.ui \
zero.ui \
... other files...
apphelp.ui \
message.ui
INCLUDEPATH = "C:/Program Files (x86)/boost/boost_1_53_0"
LIBS += \
../build/release/exprcompiler.dll
RESOURCES += \
resources/euclide_resources.qrc
我花了大量resarch天在网上来解决这个问题,但没有发现任何解释,即使有关qmake的文件是否完整...
I spent days of extensive resarch on the net to fix this problem but not found any explanation, even if documentation about qmake is complete...
有谁知道如何解决这个问题?因为我现在考虑的唯一解决办法,是让这一切项目一个特殊的调试版本,不预编译头...
感谢您的帮助。
Does anyone know how to fix this problem ? because the only solution I consider now, is to have a special "Debug" version of this all project, without precompiled headers... Thanks for your help.
推荐答案
我有(可能)遇到同样的问题,花了一些时间找出发生了什么。
I have (probably) run into the same problem and took some time to find out what is going on.
经过一些小小的创建一个MWE,我发现,.pch文件的大小似乎是这个问题的关键。
After some fiddling around to create an MWE I found, that the size of the .pch file seems to be crucial for this problem.
使用PCH大于128兆中止编译没有任何消息,并返回代码1(而不是0为成功的编译)。
Using a PCH that is greater than 128 MB aborts the compilation without any message and returns code 1 (instead of 0 for succesful compilation).
我的发现类似于 GCC邮件列表条目。
似乎让它工作的唯一方法是将PCH文件的大小减小到128 MB 。
It seems the only way to get it working is to reduce the size of the PCH file below 128 MB.
只是为了记录:
我使用来自Qt 5.2.1的QMake项目和包含的MinGW(rev2)gcc 4.8.0 32位在WinXP 32位和Win 8 64位。
Just for the record: I am using a QMake project from Qt 5.2.1 and the included MinGW (rev2) gcc 4.8.0 32bit on WinXP 32bit and Win 8 64bit.
在另一方面我GCC 4.8.2 linux下的64位吃了5GB〜PCH文件无投诉(我已经测试了
On the other hand my GCC 4.8.2 64bit under linux ate a ~5GB PCH file without complaints (I would have tested a bigger one but compiling this one nearly exceeded my RAM).
我已经生成了一个头文件使用以下内容作为PCH:
I generated a header file to use as PCH with following contents:
class _1 {};
class _2 {};
class _3 {};
class _4 {};
class _5 {};
class _6 {};
class _7 {};
class _8 {};
class _9 {};
class _10 {};
//...
使用二进制搜索)我发现
填充在具有大小为135266564字节,并且可以其他文件的编译过程中所使用的生成PCH文件128273类结果该文件。
使用128274类生成的PCH文件的大小为135270660字节,使用该PCH失败编译。
Using binary search (for the number of classes in this file) I found that filling this file with 128273 classes results in a generated PCH file that has a size of 135266564 bytes and can be used during compilation of other files. Using 128274 classes the generated PCH file has a size of 135270660 bytes and compilation using this PCH fails.
我不知道如何处理这些信息。不给错误消息肯定是错误的,但我不知道是谁的错(GCC(版本?),MinGW的/ Windows中,32bitness)。
I am not sure what to do with this information. Not giving an error message is definitely wrong but I don't know who is to blame (GCC (version?), MinGW/Windows, 32bitness).
也许有人带更多的时间可以决定和通知合适的人?
Maybe someone with more time at hand can decide and inform the right people?
这篇关于PRECOMPILED HEADERS不工作在调试生成与Qt Creator / qmake / MinGw的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!