English 中文(简体)
Getting rid of pre-compiled headers
原标题:

OK, I have old Metrowerks code for Mac and Windows where the previous developer used pre-compiled headers for every project that this code base builds.

How does one get rid of Pre-compiled headers, conceptually?

do you take the contents of a .pch and move them to a core.h and include that in all of your classes .h files?

I want to move to building with CMAKE and although there are hacks to make pre-compiled headers work, I think that it would be best to remove dependencies to them.

Some may say things about compile speed, but I am not in a race, I have fast equipment already, I am more interested in how to get away from pre-compiled headers.

问题回答

How does one get rid of Pre-compiled headers, conceptually?

Precompiled headers are an optimization. Conceptually you get rid of the precompiled headers by simply using the regular headers instead.

do you take the contents of a .pch and move them to a core.h and include that in all of your classes .h files?

I know programmers who do this. Personally I prefer to know which functions I m using and where they came from, so I make sure each file #includes all the headers needed to compile that file (and only the headers needed to compile that file). Then again, this does require constantly checking if a header is no longer necessary.

Been there... in a C++ project where a central header was included by absolutely every translation unit, and in turn included almost every Boost header there is. Nice on the platforms where PCH s are supported, but we re compiling on some where they aren t, and they took ages. (As would your core.h approach. Don t do that, especially not with C++.)

So, here goes:

  • grep for all inclusions of the PCH, and toss em (or, more gently, comment them out).
  • for each translation unit, try to build, and add missing includes until you no longer get compiler errors.

Yep, that s the brute force approach. Unfortunately I know no better.





相关问题
gcc -fPIC seems to muck with optimization flags

Following along from this question: how-do-i-check-if-gcc-is-performing-tail-recursion-optimization, I noticed that using gcc with -fPIC seems to destroy this optimization. I am creating a shared ...

Generate assembler code from C file in linux

I would like to know how to generate assembler code from a C program using Unix. I tried the gcc: gcc -c file.c I also used firstly cpp and then try as but I m getting errors. I m trying to build an ...

Getting rid of pre-compiled headers

OK, I have old Metrowerks code for Mac and Windows where the previous developer used pre-compiled headers for every project that this code base builds. How does one get rid of Pre-compiled headers, ...

Include a .txt file in a .h in C++?

I have a number of places where I need to re-use some template code. Many classes need these items In a .h could I do something like: #include <xxx.txt> and place all of this code in the ....

How to compile for Mac OS X 10.5

I d like to compile my application for version 10.5 and forward. Ever since I upgraded to Snow Leopard and installed the latest XCode, gcc defaults to 10.6. I ve tried -isysroot /Developer/SDKs/...

热门标签