Search code examples
clinuxgccmakefilegprof

GCC Compiling options syntax


I am trying to gprof my program. I want a line-by-line profiling. However, I can't seem to get the syntax right. I am using "make" and not "gcc" so please help only with suggestions that fit make. I wouldbe very grateful if you can give me the full "make" syntax. Based on this website: http://sourceware.org/binutils/docs/gprof/Output-Options.html[^] http://sourceware.org/binutils/docs/gprof/Line_002dby_002dline.html[^] Here is what I am inputting:

make USE_LOCAL_HEADERS=0 LDFLAGS='-L.' BASE_CFLAGS=-m32 CFLAGS='-fopenmp -pg -l -g'

The output is:

/usr/bin/ld: cannot find -l-g
collect2: ld returned 1 exit status
make[2]: *** [build/release-linux-ppc64/ioquake3.ppc64] Error 1
make[2]: Leaving directory `/r/home7/yasir/minoru/cfe2/yasirTemp/ioquake3dev/svfb_201110271440/ioquake3dev_clean'
make[1]: *** [targets] Error 2
make[1]: Leaving directory `/r/home7/yasir/minoru/cfe2/yasirTemp/ioquake3dev/svfb_201110271440/ioquake3dev_clean'
make: *** [release] Error 2

I need option "-l", "-g" and "-pg".


Solution

  • -pg enables profiling, -g includes symbol names which help interpreting the profile generated.

    The -pg option needs to be passed to compiler and linker.

    The -l command does not make sense in the way you are using it, as it needs a library name as parameter, so as long as you do not provide one, leave the -l away.

    Also during development I'd recommend the -Wall option to enable all warnings during compilation.

    So you might try this make command:

    make USE_LOCAL_HEADERS=0 LDFLAGS='-L. -pg' BASE_CFLAGS=-m32 CFLAGS='-fopenmp -pg -g -Wall'