How to make GCC search for headers in a directory before the current source file's directory?

大兔子大兔子 提交于 2019-12-02 23:28:51

I have found a workaround.

  1. Build a precompiled header under a different name. For example is the header is a.h, original precompiled header is pchdir.i686/a.h.gch, build it as

    gcc a.h -o pchdir.i686/a-precompiled.h.gch
    
  2. Use GCC's -include switch to make sure the renamed header is included before anything else (even before the original a.h), e.g.

    gcc -Ipchdir.i686 -include a-precompiled.h <other arguments> <source>
    
  3. Final inclusion order in the source file will be: a-precompiled.h.gch, a.h, which I've checked with -H. Original header is included, but is not actually processed because precompiled header has identical include guards (verified as well by inserting an #error in the original header after building the precompiled one).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!