Precompiled headers with GCC

后端 未结 6 1943
自闭症患者
自闭症患者 2020-11-28 18:24

Anyone had any success getting precompiled headers working with GCC? I have had no luck in my attempts and I haven\'t seen many good examples for how to set it up. I\'ve t

6条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-11-28 19:04

    I have managed to get precompiled headers working under gcc once in the past, and I recall having problems then as well. The thing to remember is that gcc will ignore the file (header.h.gch or similar) if certain conditions are not met, a list of which can be found on the gcc precompiled header documentation page.

    Generally it's safest to have your build system compile the .gch file as a first step, with the same command line options and executable as the rest of your source. This ensures the file is up to date and that there are no subtle differences.

    It's probably also a good idea to get it working with a contrived example first, just to remove the possibility that your problems are specific to source code in your project.

提交回复
热议问题