Precompiled headers with GCC

后端 未结 6 1934
自闭症患者
自闭症患者 2020-11-28 18:24

Anyone had any success getting precompiled headers working with GCC? I have had no luck in my attempts and I haven\'t seen many good examples for how to set it up. I\'ve t

6条回答
  •  抹茶落季
    2020-11-28 19:10

    The -x specifier for C++ precompiled headers is -x c++-header, not -x c++. Example usage of PCH follows.

    pch.h:

    // Put your common include files here: Boost, STL as well as your project's headers.
    

    main.cpp:

    #include "pch.h"
    // Use the PCH here.
    

    Generate the PCH like this:

    $ g++ -x c++-header -o pch.h.gch -c pch.h
    

    The pch.h.gch must be in the same directory as the pch.h in order to be used, so make sure that you execute the above command from the directory where pch.h is.

提交回复
热议问题