What are gch files and how do they work?

Asked

Viewed 520 times

0

I recently came across a file with the extension .gch in one of my projects, this occurred because I ended up passing a file .h to be compiled in gcc.

$ gcc -c arquivo.h
$ ls
arquivo.c
arquivo.h
arquivo.h.gch

What is File With Extension .gch compiler-generated?

How can I use this file format?

2 answers

1

File with extension.gchrefers to the precompiled header of GCC, and one way to generate them is by passing a header file, .h, as a source to the compiler. 3

Using it is transparent to the developer, since the compiler, when it finds#include "arquivo.h", first check if there is noarquivo.h.gch in the same way, and only in the absence of it, interprets thearquivo.h. 4

NOTE

The pre-compiled header (English acronym, PCH, for pre-compiled header) is a important tool to decrease build time complex projects with many files. But must obey some rules so that this gain can be achieved, or in some cases, they will even have a higher build time than not using it. 5 6

Broadly, small projects do not require such a resource, therefore, if in a project created by you appears a pre-compiled header that you are not aware of, try to configure its compilation, refraining from using the resource. 7

0


Files with extension .h.gch are pre-compiled header files by GCC, they serve to import the headers as a file .h.

When importing a library into C/C++ (as my_math. h) could use a pre-compiled file my_math.h.gch.

To import this header next to the file .c, can normally import as if it were a normal header file #include my_math.h (don’t need to pass the .gch)

Sources:

https://codare.aurelio.net/2007/05/11/cpp-pre-compilacao-de-headers-no-gcc/

Browser other questions tagged

You are not signed in. Login or sign up in order to post.