New Gradle 2.5 precompiled-header feature not working

I’ve just tried to use the new precompiled header feature from Gradle 2.5, but unfortunately it’s not working - although the precompiled header is compiled fine, the rest of the compilation that uses it is giving the following error:

error C2859: …\vc120.pdb is not the pdb file that was used when this precompiled header was created, recreate the precompiled header.
error C2859: …\vc120.idb is not the idb file that was used when this precompiled header was created, recreate the precompiled header.

And indeed, when I check the directories helloCppPCH and helloCpp, those two files are different.

Any suggestions? Has anyone else got this working on Windows with Visual Studio 2013?

@Gary_Hale Does this look familiar?

@tom_wright can you share some more details about your build?

Thanks for following up - what details would be useful? It’s a multi-project build and we’re using the visual-studio, cpp and windows-resource plugins. We have dependencies between projects in the multi-project build, and also some dependencies on external libraries that are not built as part of that build. We’re also overriding the default resource file location so that we can inject a file created as part of the build, and the external header file location due to some idiosyncrasies of the way headers are included in some of our source files.

Have you tried setting the “/Fd” compiler flag to point the compilers to use the same pdb file? You should be able to do something like the following:

binaries.all { binary ->
    if (toolChain in VisualCpp) {
        cppCompiler.args "/Zi", "/Fd${buildDir}/objs/${binary.name}/${binary.name}-${binary.buildType.name}.pdb"
    }
}
1 Like

Thanks for your reply, and sorry for the delayed response. Your workaround suggestion of pointing to an explicit pdb file basically works (although the variables in the path didn’t quite work for me…I need to investigate further to get them to match up to what is actually on the disk).

So do you think this is a bug in Gradle? Or some quirk of my build?

Well, neither really. It’s more a quirk of Visual C++ and that it has a requirement that you also set the debug database file name when you set any debug compiler arguments and you are using precompiled headers. As it is right now, Gradle doesn’t interrogate the compiler arguments you set, it just passes them on to the compiler. When precompiled headers are used, it ensures that the same arguments are used for both compiles, but again it doesn’t have an understanding of what those arguments mean. It doesn’t know whether you’ve specified a debug argument or not, or whether for a certain toolchain, when you add a debug argument you also need another argument, so it won’t add this automatically.

If we were to support setting this automatically, I’d expect we would model something like a “debug” option either on the binary or on the build type that automatically adds both the debug argument as well as an /Fd argument to the compiler arguments when precompiled headers are in use. Unfortunately, the model just doesn’t include this sort of knowledge yet.