gprof:undefined reference to `mcount'

1,622 views
Skip to first unread message

Copper Hill

unread,
May 25, 2009, 10:53:52 PM5/25/09
to worldhunter
When using gprof, if an error like "undefined reference to `mcount' "
occurs, it should be lack of link option for the target.

-pg option should be used as a compiler option, also as a linker
option.

Hong Zhaogang

unread,
May 25, 2009, 11:17:52 PM5/25/09
to worldhunter
When running gprof, if it says "has no symbols", then check if there
is "-s" in the compiler options and the linker options.

-s Remove all symbol table and relocation information from the
executable.

Hong Zhaogang

unread,
May 26, 2009, 3:21:16 AM5/26/09
to worldhunter
http://www.cs.duke.edu/~ola/courses/programming/gprof.html

How to Use GProf in 5 Easy Steps.

1. Get your program working!! gprof is not a debugger. Use it once
you have a working program to optimize that program.
2. Compile and link with the -pg option. If you use an Owen
Astrachan patented makefile this simply means changing the CFLAGS
variable.
3. Run your program normally; that is, pretend you didn't do
anything to it and do what you would normally do (checking difficult,
slow, or fast cases, of course).
4. Type gprof exec > out where exec is replaced by your
executable's name and out by some meaningful name for the profiling
information. For instance, if your executable were "foo" on the third
run compiled with the -O2 option then you might type:

gprof foo > run3.withO2.stats

5. Look over the output and learn what it means. Hint, go to the
second table. The first is pretty useless. To get there, search for
"granularity" twice from the top of the file (in emacs, use C-s; in
less or more use /).
Reply all
Reply to author
Forward
0 new messages