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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Thanks! It's indeed a clever way.

Being still curious, I am waiting for some explanation on which happens at which stage.

--- On Fri, 8/28/09, Tim Prince <n8tm@xxxxxxx> wrote:

> From: Tim Prince <n8tm@xxxxxxx>
> Subject: Re: Debugging, optimization and profiling - which happens at which stage(s) (compilation and link)
> To: "Tim" <timlee126@xxxxxxxxx>
> Cc: gcc-help@xxxxxxxxxxx
> Date: Friday, August 28, 2009, 1:28 PM
> 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 of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux