How to make GCC not generate .h.gch files

前端 未结 2 1024
别那么骄傲
别那么骄傲 2021-02-09 07:28

Using GCC to compile C code, GCC automatically generate .h.gch files.

Question

How do I suppress this?

相关标签:
2条回答
  • 2021-02-09 08:16

    I came here looking for an answer to the same problem. I found an answer at another website. If you add the -fsyntax-only option to the compile line, no output files are generated.

    gcc -fsyntax-only myheader.h
    

    I purposefully compile .h files I'm working on to check for syntax errors. In this case generation of the .gch file is quite annoying since if the .h file is subsequently modified, and you don't recompile it (to generate a new .gch), then the old .gch file hides the newer .h file for subsequent .c/.cpp compilations (which can really be quite confusing...)

    Now I guess you could write a dummy .c/.cpp file to include a new header that you've just written, and then compile that to test it out, but I'm way too lazy for such nonsense. The -fsyntax-only appears to be a much nicer solution.

    0 讨论(0)
  • 2021-02-09 08:28

    Files ending in .gch are precompiled headers - header files which have been pre-compiled in order to reduce compilation time when you (re)compile your main program.

    They are produced if you invoke the compiler with the header file itself as the target, ie:

    gcc myheader.h
    

    Normally you would only be calling the compiler with .c files as targets.

    If you don't want it to produce precompiled headers then don't invoke the compiler with the header files as the target.

    If you are not deliberately calling the compiler with the headers as targets, you might be using a makefile which is setup to produce these files - it will have rules in it to produce .gch files from .h files. You will need to remove these rules and adjust other rules not to depend on them.

    0 讨论(0)
提交回复
热议问题