Questions tagged [precompiled-headers]

A precompiled header is a header file that has statically compiled but still separate from its final executable in order to speed up compilation of dependent files.

In C and C++, precompiled headers allow for quicker compilation times by keeping the definitions from a given header in an compiled state. This allows the compiler to quickly incorporate the header when a file dependent on the header is being compiled.

Rather than having to parse through code, precompiled headers allow the compiler to skip directly to a more intermediate state. For headers that are used frequently this can result in significant compile-time savings.

454 questions
10
votes
4 answers

Precompiled headers with DLL solutions. Cannot open precompiled header file

This worked without error when this solution worked off of .lib files instead of .dll files. I have all of my projects except one currently using a precompiled header, without error. The precompiled header is called "LudoGlobal.h". I am trying…
user189320
9
votes
1 answer

How to use precompiled header files in Android NDK

I have a .pch file which is required to compile a c++ file. I am using Android NDK to make a library out of few c++ files and then use it in my Java programs to call library functions. Can anyone tell how or where to include .pch files so that…
Nishant Soni
  • 658
  • 1
  • 9
  • 19
9
votes
2 answers

Creating several precompiled header files using GNU make

I use gcc (running as g++) and GNU make. I use gcc to precompile a header file precompiled.h, creating precompiled.h.gch; the following line in a Makefile does it: # MYCCFLAGS is a list of command-line parameters, e.g. -g -O2…
anatolyg
  • 26,506
  • 9
  • 60
  • 134
9
votes
3 answers

Why does Visual Studio C++ require including "StdAfx.h" even on files that don't need it?

I understand what precompiled headers are doing with "#include "StdAfx.h" and yes, I know I can turn them off. But that's not my question. If you're using precompiled headers, Visual C++ requires every cpp file to #include "StdAfx.h", even the files…
9
votes
2 answers

Sharing Pre-compiled Headers efficiently

I have a framework which is being used by several projects (which includes several samples to show how the framework works). The framework has components such as the core, graphics, physics, gui etc. Each one is a separate library. There are several…
Samaursa
  • 16,527
  • 21
  • 89
  • 160
9
votes
2 answers

Getting started with PCH in a VC++ project

I'm working on a VC++ project in VS 2012 that takes about 8-10 minutes for a full compile. I know PCH can speedup compile times by upto 10x. I have currently disabled PCH in my project and I'm including header files where they are needed. How do I…
Robin Rodricks
  • 110,798
  • 141
  • 398
  • 607
9
votes
2 answers

Precompiled headers with Autotools

Is it possible to use gcc precompiled headers in projects using automake / libtool? Adding new make rules to build precompiled headers is not difficult. The issue is that you also have to add compilation flags introduced by libtool and AFAIK it…
Dj Gaspa
  • 253
  • 1
  • 2
  • 9
8
votes
1 answer

Objective-C typedef enum in global constants file

OK, this is related to question "Constants in Objective C". I created Constants.h and its corresponding Constants.m file: // Constants.h extern int const BOOKS; typedef enum SSDifficultyLevel { EASY = 0, MEDIUM = 1, HARD = 2 }…
rtovars
  • 440
  • 3
  • 17
8
votes
1 answer

Does pre-compiling c++ header files slows down linking time?

I have 100 .h files in a externalFiles diretory. Around 10 .cpp files in my source includes these .h files. So I removed all #include externalFiles/.*h directives from my .cpp files and wrote them in a pch.h header that I include via Cmake's…
8
votes
2 answers

Using a namespace to make global functions, but getting multiply defined symbols error

These functions are Utility type things that most of my programs objects will use. I want to have them in a namespace and have them global. This namespace is defined in a header and then added to my precompiled header. However so far I have used…
EddieV223
  • 5,085
  • 11
  • 36
  • 38
8
votes
3 answers

Weird Behavior with gcc precompiled headers

I was having troubles getting pre-compiled headers to work, so I came up with the following minimal-working-example. This is the header file foo.h #include using namespace std; void hello() { cout << "Hello World" << endl; } I…
sud03r
  • 19,109
  • 16
  • 77
  • 96
8
votes
1 answer

Unexpected #else

For some reason I can't explain, the compiler is outputting an error saying that it found an unexpected #else token. This occurs at the beginning of the file : #if defined( _USING_MFC ) #include "stdafx.h" #else #include…
Virus721
  • 8,061
  • 12
  • 67
  • 123
8
votes
0 answers

Can precompiled headers be made to work with distcc?

I have a large project for which I've implemented precompiled headers. I'd also like to be able to get it to work with distcc. According to section 4.12 in the google code paper here gcc version 3.3 includes some performance improvements that make…
TooTone
  • 7,129
  • 5
  • 34
  • 60
8
votes
2 answers

What to add to precompiled headers

I am new to precompiled headers, and am just wondering what to include. Our project has about 200 source files. So, do I literally include every third party library? If I use a map in three source files, do I add it? What if I use it one, do I add…
Cookie
  • 12,004
  • 13
  • 54
  • 83
8
votes
3 answers

Precompiled headers and compiling universal objects on OSX

We are using precompiled headers with GCC for our project and build them like this: gcc $(CFLAGS) precompiledcommonlib.h Now I'm building the project on OSX 10.6 and trying to use the nifty feature of building for all architectures at the same time…
rasmusb
  • 438
  • 1
  • 3
  • 10