简体   繁体   中英

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

In Qt Creator, I have a pro file using PRECOMPILED HEADERS.

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.

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

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.

After some fiddling around to create an MWE I found, that the size of the .pch file seems to be crucial for this problem.

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).

My findings resemble the problem stated in this GCC mailing list entry .

It seems the only way to get it working is to reduce the size of the PCH file below 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.

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).

Digging deeper

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 {};
//...

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.

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?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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