일상에서 멍때리기

gcc에서 특정 header file을 모든 파일에 한번에 include하는 방법 본문

프로그래밍/삽질로그

gcc에서 특정 header file을 모든 파일에 한번에 include하는 방법

로 얄 2014. 4. 14. 23:35
반응형

gcc로 컴파일할 때, define이 설정된 파일등의 경우 모든 파일에 include을 해줘야하는 번거로움이 발생합니다.
iOS xcode같은 경우에는 프로젝트에  Prefix.pch file이 존재하여 해당 파일에 include를 해주면 모든 코드에서 자동으로 include가 된다고 합니다.

그렇다면 gcc에서는 어떻게 써야할까요?
정답은 다음과 같습니다.

-include file


gcc manual page를 찾아보니 Preprocessor Options중에 나오더군요.
테스트 결과 header file을 일일이 넣지 않아도 해당 header가 포함된 것을 확인했습니다.

manual page의 내용은 아래와 같습니다. 
참고하세요!

-include file

           Process file as if "#include "file"" appeared as the first

           line of the primary source file.  However, the first directory

           searched for file is the preprocessor's working directory

           instead of the directory containing the main source file.  If

           not found there, it is searched for in the remainder of the

           "#include "..."" search chain as normal.


           If multiple -include options are given, the files are included

           in the order they appear on the command line.

 

반응형
Comments