Precompiled Headers in Header Files

后端 未结 3 652
抹茶落季
抹茶落季 2020-12-15 08:21

I ran into precompiled headers today for the first time..forever changing my life. I can\'t believe compiling my C++ code could be that fast. It makes total sense now..

3条回答
  •  执笔经年
    2020-12-15 08:50

    Yes, it is expected behaviour. The Project Properties->C/C++->Advanced to "Force Include File" setting controls Visual C++ compiler option /FI:

    This option has the same effect as specifying the file with double quotation marks in an #include directive on the first line of every source file

    So, it frees you from including the stdafx.h manually.

    Although, you can use precompiled headers with GCC and other compilers The Visual C++'s shortcut behaviour is not portable across other compilers. So, check How to handle stdafx.h in cross-platform code? where ideas for portable solutions are discussed.

    Long story short, include stdafx.h manually in your .cpp source files and you should be fine also with GCC (assuming, you will configure your build for GCC to use precompiled headers).

提交回复
热议问题