2

I have a header in my project, called Core.h, that I use as a pre-compiled header:

$(CXX) $(CXX_CFLAGS) -x c++-header Core.h

Which creates a file named Core.h.gch

*#include "Core.h" is the first directive of every source file in the module.

On OS X, it works fine -- my project compiles fine & it compiles pretty fast.

On Linux however, 7 of my 100+ files give the following warning:

warning: Core.h.gch: too short to be a PCH file

Just like every other source file, #include "Core.h" is the first line of these files.

Has anyone ever come across this? Possible causes? Why would it only be a few files that include the PCH that would give the warning ?

I use gcc version 4.1.2 on Linux, 4.2.1 on OSX

Thanks!

EDIT:

Here is basically how I build the library:

.PHONY: all 
all: $(MY_PCH) MYLIB.so MYLIB.a

MYLIB.so: $(MY_PCH) $(MY_OBJECTS)
  $(CXX) $(MY_OBJECTS) $(CXX_LDFLAGS) -o $@

MYLIB.a: $(MY_PCH) $(MY_OBJECTS)
  $(AR) $(ARFLAGS) $@ $(MY_OBJECTS)

$(MY_PCH):
  $(CXX) $(CXX_CFLAGS) -x c++-header Core.h
zedxz
  • 113
  • 1
  • 8

1 Answers1

3

Are you using a parallel make? Possibly g++ is trying to read the .gch file while another instance is writing to it.

Ben Voigt
  • 277,958
  • 43
  • 419
  • 720
  • I make -j8, therefore with 8 threads. But even without -j8 I still get the warnings. – zedxz Sep 09 '11 at 04:25
  • 1
    @zedxz: Well, there's your problem. The makefile doesn't indicate that the other object files are dependent on the precompiled header, so it tries to build them in parallel with the precompiled header, and you have a race condition. Use make's dependency rules to force the precompiled header to be built before the compilation units which need it. – Ben Voigt Sep 09 '11 at 04:26
  • absolutely correct. Adding the PCH as a depdency to the objects rather than the libraries fixes the race condition. Thank you very much! – zedxz Sep 09 '11 at 04:30