I am trying to create a precompiled header file for my shared library using GCC. After making the necessary configuration and trying to build, I got these warnings:
cc1plus: warning: ./PrecompiledHeaders.h.gch/.c++: created and used with different settings of -fpic [enabled by default]
After some time searching, I found this piece of code which seems to suggest that PCH doesn't work with shared code:
/* -fpic and -fpie also usually make a PCH invalid. */
if (data[0] != flag_pic)
return _("created and used with different settings of -fpic");
if (data[1] != flag_pie)
return _("created and used with different settings of -fpie");
data += 2;
So I changed my library to a static library and the error disappeared and compilation time was reduced! So is it indeed not possible to have a PCH with shared library? If yes, is there any work around this?