简体   繁体   English

PRECOMPILED HEADERS无法使用Qt Creator / qmake / MinGw进行调试构建

[英]PRECOMPILED HEADERS not working in debug build with Qt Creator / qmake / MinGw

In Qt Creator, I have a pro file using PRECOMPILED HEADERS. 在Qt Creator中,我有一个使用PRECOMPILED HEADERS的专业文件。

The build works just perfect when I build in Release mode. 当我在Release模式下构建时,构建工作非常完美。 But building in Debug mode gives errors, generating object files failing. 但是在Debug模式下构建会产生错误,导致生成目标文件失败。 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.

What is really confusing is that it works fine in Release. 令人困惑的是它在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. 我用一个小项目做了一些测试,它在Release或Debug模式下运行良好,但由于任何原因,一个更大的项目失败了。 It is even impossible to compile a single file of the project in Debug. 甚至不可能在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

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... 我在网上花了几天时间来解决这个问题,但没有找到任何解释,即使有关qmake的文档已经完成......

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. 我(可能)遇到了同样的问题,并花了一些时间来了解发生了什么。

After some fiddling around to create an MWE I found, that the size of the .pch file seems to be crucial for this problem. 经过一番摆弄来创建一个我发现的MWE后,.pch文件的大小似乎对这个问题至关重要。

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). 使用大于128 MB的PCH将在没有任何消息的情况下中止编译并返回代码1(而不是0以进行成功编译)。

My findings resemble the problem stated in this GCC mailing list entry . 我的发现类似于GCC邮件列表条目中提到的问题。

It seems the only way to get it working is to reduce the size of the PCH file below 128 MB . 似乎让它工作的唯一方法是将PCH文件的大小减小到128 MB以下

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. 仅供记录:我正在使用Qt 5.2.1中的QMake项目和WinXP 32位和Win 8 64位上包含的MinGW(rev2)gcc 4.8.0 32位。

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). 另一方面,我在Linux下的GCC 4.8.2 64位吃了一个~5GB的PCH文件而没有抱怨(我会测试一个更大的但是编译这个几乎超过了我的RAM)。

Digging deeper 深层发掘

I generated a header file to use as PCH with following contents: 我生成了一个头文件用作PCH,内容如下:

class _1 {};
class _2 {};
class _3 {};
class _4 {};
class _5 {};
class _6 {};
class _7 {};
class _8 {};
class _9 {};
class _10 {};
//...

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. 使用二进制搜索(对于此文件中的类数),我发现用128273类填充此文件会生成一个生成的PCH文件,其大小为135266564字节,可以在编译其他文件时使用。 Using 128274 classes the generated PCH file has a size of 135270660 bytes and compilation using this PCH fails. 使用128274类生成的PCH文件的大小为135270660字节,使用此PCH进行编译失败。

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). 没有给出错误信息肯定是错的,但我不知道应该责怪谁(GCC(版本?),MinGW / Windows,32位)。

Maybe someone with more time at hand can decide and inform the right people? 也许有更多时间的人可以决定并告知合适的人?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM