Using Gradle 4.10.2 (or 5.5.1 - same problem with both), I’m trying to enable precompiled header support to an existing native project that was building successfully prior to this change. I use the /ZI
compiler flag on all files compiled for debug build types.
I created a PCH file in the project’s headers directory, updated all the implementation files to include the PCH as the first include in the file, and added the preCompiledHeader
property to the build script like so:
components {
myProject(NativeLibrarySpec) {
...
sources {
...
cpp {
preCompiledHeader "pch.h"
...
}
}
}
}
The precompiled header task completes successfully, however, when the debug compile tasks start up, I get these errors for each file:
e:\dev\myProject\src\myLib\cpp\mySource.cpp(1): error C2859: E:\dev\myProject\build\objs\myLib\static\windows_x64\debug_static\myLibCpp\vc140.pdb is not the pdb file that was used when this precompiled header was created, recreate the precompiled header.
e:\dev\myProject\src\myLib\cpp\mySource.cpp(1): error C2859: E:\dev\myProject\build\objs\myLib\static\windows_x64\debug_static\myLibCpp\vc140.idb is not the idb file that was used when this precompiled header was created, recreate the precompiled header.
When I inspect the layout of the build
folder, there are two sets of pdb and idb files, one copy in build/objs/myLib/static/windows_x64/debug_static/myLibCppPCH
and another in build/objs/myLib/static/windows_x64/debug_static/myLibCpp
.
Why doesn’t gradle ensure that the compilation pass made after the PCH task completes is configured consistently with the PCH pass? How can I get rid of this error?