Makefile/double compilation

712 views Asked by At

Recently I noticed (after others have extended the project) that the compile time significantly increased. I was suggested to make use of c++ precompiled headers. The "include" parts are moved to a separate file "precompiled.h"

#include <iostream>

#include <stxxl/vector>
#include <stxxl/priority_queue>
#include <stxxl/sort>
#include <stxxl/scan>
#include <stxxl/stream>

#include <string> 
#include <sstream>
#include <cstdlib>
#include <ctime>
#include <cmath>  
#include <vector>   
#include <limits.h>
#include <queue>
#include <algorithm>
#include <numeric>
#include <typeinfo>
#include <fstream>              
#include <cairo.h>
#include <cairo-pdf.h>
#include "myFile1.cpp"
#include "myFile2.cpp"

and the header file specific makefile has the following content:

STXXL_ROOT      ?= /home/mirza/stxxl-1.2.1
STXXL_CONFIG    ?= stxxl.mk
include $(STXXL_ROOT)/$(STXXL_CONFIG)

# use the variables from stxxl.mk

CXX              = $(STXXL_CXX)
CPPFLAGS        += $(STXXL_CPPFLAGS)

# add your own optimization, warning, debug, ... flags
# (these are *not* set in stxxl.mk)
CPPFLAGS        += $(shell pkg-config --cflags cairo)
STXXL_LDLIBS    += $(shell pkg-config --libs cairo)

CPPFLAGS        += -O3 -Wall -g -c -DFOO=BAR

# build your application
# (my_example.o is generated from my_example.cpp automatically)

precompiled.o: precompiled.h
    $(CXX) $(CPPFLAGS) $(CXXFLAGS) precompiled.h -o $@ $(STXXL_LDLIBS)

Of course, the first line in the main .cpp file is "include "precompiled.h"". However, after executing main file specific make file, I get the reports and warnings that I got when compiling "precompiled.h" file (warnings and reports related to myFile1.cpp myFile1.cpp). I guess the compilation process is repeated. I've read that the precompiled headers are associated with .gch files, which I did not manage to generate. Any help on this is highly appreciated. Thanks

I guess it would be helpful to include the content of the makefile specific for the main .cpp file. Perhaps by changing this file I could "tell the compiler" that the load was done once.

STXXL_ROOT      ?= /home/mirza/stxxl-1.2.1
STXXL_CONFIG    ?= stxxl.mk
include $(STXXL_ROOT)/$(STXXL_CONFIG)

# use the variables from stxxl.mk

CXX              = $(STXXL_CXX)
CPPFLAGS        += $(STXXL_CPPFLAGS)

# add your own optimization, warning, debug, ... flags
# (these are *not* set in stxxl.mk)

CPPFLAGS        += $(shell pkg-config --cflags cairo)
STXXL_LDLIBS    += $(shell pkg-config --libs cairo)


CPPFLAGS        += -O3 -Wall -g -DFOO=BAR

# build your application
# (my_example.o is generated from my_example.cpp automatically)
fileA.bin: fileA.o
    $(CXX) $(CPPFLAGS) $(CXXFLAGS) fileA.o -o $@ $(STXXL_LDLIBS)
1

There are 1 answers

0
Terence Simpson On BEST ANSWER

You need to change the precompiled.o: precompiled.h rule to precompiled.h.gch: precompiled.h so GCC knows it's the precompiled header