This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Debugging, optimization and profiling - which happens at which stage(s) (compilation and link)


Tim wrote:
Hi,

In most Makefiles I have seen, CXXFLAGS is used in the compile rule, either implicitly or explicitly. A few days ago, however I saw a Makefile that uses CXXFLAGS in link stage. Its compile rule is implicit which I suppose to use CXXFLAGS as well. The Makefile is as follows:

ifeq ($(STATIC),yes)
  LDFLAGS=-static -lm -ljpeg -lpng -lz
else
  LDFLAGS=-lm -ljpeg -lpng
endif

ifeq ($(DEBUG),yes)
  OPTIMIZE_FLAG = -ggdb3 -DDEBUG -fno-omit-frame-pointer
else
  OPTIMIZE_FLAG = -ggdb3 -O3
endif

ifeq ($(PROFILE),yes)
  PROFILE_FLAG = -pg
endif

CXXFLAGS = -Wall $(OPTIMIZE_FLAG) $(PROFILE_FLAG) $(CXXGLPK)

all: test

test: test.o rgb_image.o $(CXX) $(CXXFLAGS) -o $@ $^ $(LDFLAGS)

Makefile.depend: *.h *.cc Makefile


Does it mean that the optimization, debug options or/and profiling options are necessary in both compile and link stages? So is it better to use CXXFLAGS in link stage too?



When $(CXX) is used to drive the link step, it's entirely appropriate to pass it the same flags used at compile time, even though many of them will be ignored. In this case, the flag -pg must be consistent between compile and link steps.
I believe most C++ compilers implicitly include -lm, so that is redundant yere.



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]