Search code examples
c++gcccodeblocksprecompiled-headers

How to create precompiled header with codeblocks and gcc


I have a file which has been tested and works as intended:

#ifndef PROMOTE_H_INCLUDED
#define PROMOTE_H_INCLUDED
#include <boost/mpl/vector.hpp>
#include <boost/mpl/find.hpp>
#include <boost/mpl/next.hpp>
#include <boost/mpl/deref.hpp>


template<class Integral>
struct Promote
{
    typedef  boost::mpl::vector<char,short,int,long,long long> types;
    typedef typename boost::mpl::find<types,Integral>::type this_type;
    typedef typename boost:: mpl::next<this_type>::type next_type;
    typedef typename boost::mpl::deref<next_type>::type type;

};
#endif // PROMOTE_H_INCLUDED  

Every time I change something in my project this file is being compiled over and over again which is bit sill. I tried to search net and I found:
http://gcc.gnu.org/onlinedocs/gcc/Precompiled-Headers.html But to be honest I just don't see anywhere there instruction how to create precompiled header. So could anyone, step by step tell me how to do it using code::blocks?
thanks.


Solution

  • From the docs you link:

    To create a precompiled header file, simply compile it as you would any other file, if necessary using the -x option to make the driver treat it as a C or C++ header file.

    So:

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

    for C++ code will create the precompiled header.

    It wont speed up the build process in the way you seem to want it though. If you change that header, you'll need to update the precompiled header too, and all its dependencies.