![]() |
|
Precompiled Headers in GCC |
Marcello
Member #1,860
January 2002
![]() |
entheh recently mentioned gcc's support for precompiled headers... I was looking through the file trying to figure stuff out, and although it seems sort of simple, it does not seem completely simple. Does anyone use this feature on gcc? If so, any recommendataions as to how to use it, such as in a makefile or whatnot. It also was not clear if you could use them for example for allegro's own header files to speed up that bit. And where you would put those precompiled headers as well... So ya, basicaly just trying to get an idea of how many people already use this feature. Marcello |
Oscar Giner
Member #2,207
April 2002
![]() |
I read that doc, and it's done almost like in MSVC. You pre-compile ONE header file. in MSVC, that header is usually called stdafx.h. You only put include statements in that header, usually includes to lib headers: stdafx.h #include <allegro.h> #include <list> #include <vector> You must compile this header as a C or C++ file depending on your project. Then, in all cpp files that need one of these headers, you include the stdafx.h header instead. And that's all:) -- |
Marcello
Member #1,860
January 2002
![]() |
That sounds like a lot of extra work though. Would you do that only for libraries? What about your own header files for classes and whatnot? Could you maybe generate precompiled header files for those separately, as well? That way you could still include the files normally. Maybe that makefile dependency generator thing could be used to get system headers or something... Anyone do it differently? Marcello |
Oscar Giner
Member #2,207
April 2002
![]() |
Only one precompiled header is allowed per project. You can include headers from the project to the precompiled header if they don't change very often. Precompiled headers take more time to compile, but you do it only once. [edit] gcc precompiled header docs said: Only one precompiled header can be used in a particular compilation. Actually it says 'per compilation', not per project, so that would mean that you can only include one precompiled header in a given c/cpp file. -- |
gillius
Member #119
April 2000
|
Yep this sounds like MSVC's pch support. I have a global header file in MSVC, (the wizard makes stdafx.h, but I usually rename it to global.h or globals.h or my_project_name.h). In this global.h file I put in ALL headers that don't change, or very rarely change -- this means headers like <iostream> and <allegro.h> or other external libraries. Then I include global.h in EVERY file in my project. This is actually easier than trying to find out what headers are needed for what files, and it compiles faster too. Gillius |
Mark Robson
Member #2,150
April 2002
|
I have gcc 3.3.2 and I'm fairly sure it doesn't support precompiled headers. Either they (Debian) removed support for it at build time, or it's a new feature that's been added in 3.4 Yes, you can only have one precompiled header, but it's easy enough as you just put all your includes in there. I read the docs, it looks simple, a few lines in Makefile would take care of it. Unfortunately this doesn't alter the fact that it doesn't work on my version. Mark |
Bob
Free Market Evangelist
September 2000
![]() |
MSVC (6, at least) supports an unlimited number of precompiled headers, which can be shared among several compilation units. You just need to point it to the pch file. Granted, this is using cl.exe, and not through the IDE. -- |
fox
Member #1,615
November 2001
![]() |
It looks like gcc supports precompiled headers since v3.4 (bad luck Mark |
|