This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: How to use precompiled header?


Hei Chan <structurechart@yahoo.com> writes:

> But I still don't fully understand how I can use a 
> precompiled header in a 3rd party library.
>
> For example, I have:
> - /opt/3rdPartyLib/src/A/B.h
> - /opt/3rdPartyLib/src/A/B.h.gch
>
> Then, I tried to compile my code with:
> g++ -I/opt/3rdPartyLib/src -H 
> -include A/B.h -o myApp.o myApp.cpp
>
> But I got:
> x 
> /opt/3rdPartyLib/src/A/B.h.gch
>
> So it seems like for some reasons, /opt/3rdPartyLib/src/A/B.h.gch isn't used.
>
> My user doesn't have 
> read-write permission to /opt/, but it does have read permission to 
> /opt/3rdPartyLib/src/A/B.h.gch tho...so I think that the permission is 
> fine.
>
> Any suggestion?

Try using the -Winvalid-pch option.

Most likely the PCH was generated by a different version of the
compiler.  In gcc a PCH is only valid for the exact compiler which
generated it.  This does make it quite difficult to use PCH's built by
third parties.  However, you should be able to build your own PCH from
the third party header file, and use -include to pick it up first.
Assuming the third party header uses the usual #ifndef/#define
construct to only get included once, that should let you use PCH
without having to change your source code.

Ian


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]