Skip to content

Precompiled header

In computer programming, a precompiled header is a (C or C++) header file that is compiled into an intermediate form that is faster to process for the compiler. Usage of precompiled headers may significantly reduce compilation time, especially when applied to large header files, header files that include many other header files, or header files that are included in many translation units.

GCH

gcc-3.4 버전 이후부터 PCH 기능을 지원한다. PCH의 기본 개념은 많은 소스 파일에서 공통적으로 참조하는 헤더 파일들을(하나로 묶어) 미리 처리하여 컴파일 시간을 단축시키고자 하는 것이다.

C++의 경우:

g++ -x c++-header stdafx.h -o stdafx.h.gch

C의 경우:

gcc -x c-header stdafx.h -o stdafx.h.gch

위와 같이 컴파일을 하면 꽤 큰 용량의 stdafx.h.gch 파일이 생긴다. 이 파일이 Pre-Compiled header 이다. Pre-Compiled header 를 쓰기 위해서는 원하는 곳에 #include "stdafx.h"를 추가하는 것으로 끝난다. 즉 stdafx.h 파일이 있는 곳에 stdafx.h.gch 가 있으면 gch 를 먼저 확인한다.

See also

Favorite site

References


  1. WxWiki_-_Precompiled_Headers.pdf 

  2. Gcc_how_to_use_pre_compiled_header.pdf