I have a very simple makefile, that basically does the following:
# Pre-compiled header
CORE_PCH_FILENAME =Core.h
CORE_PCH:
$(CXX) $(CXX_CFLAGS) -x c++-header $(CORE_PCH_FILENAME)
#Objects
obj/%.o: CORE_PCH %.cpp obj/%.d
@mkdir -p obj
$(CXX) $(CXX_CFLAGS) -c $*.cpp -o $@
#De开发者_Go百科pendencies
obj/%.d: %.cpp
@mkdir -p obj
$(CXX) $(CXX_CFLAGS) -MM -MT obj/$*.o -MF $@ $<
My problem is, the first time I make, the Core.h.gch gets created and the project gets built. That's fine.
But, even if change nothing, running make again will re-create the Core.h.gch and recompile everything.
If I don't have a pre-compiled header, make behaves fine (will not rebuild anything if nothing has changed, and rebuild only what's necessary if modifications were made)
But I'd really like to have that pre-compiled header, is there something I'm not doing right!?
EDIT:
The following was suggested:
# Pre-compiled header
$(CORE_PCH_FILENAME) =Core.h
CORE_PCH: $(CORE_PCH_FILENAME)
$(CXX) $(CXX_CFLAGS) -x c++-header $(CORE_PCH_FILENAME)
But it still gets created every time :(
The problem is that you do not refer to the gch
by name, and there is no file named CORE_PCH
, literally.
Try:
CORE_PCH_FILENAME=Core.h
CORE_PCH=$(CORE_PCH_FILENAME).gch
$(CORE_PCH):
$(CXX) $(CXX_CFLAGS) -x c++-header $(CORE_PCH_FILENAME)
CORE_PCH is in the pre-requisites for obj/%.o, and it has no pre-requisites itself, so it always gets built. If you add Core.h to the pre-requisites for CORE_PCH, that should take care of it.
精彩评论