Re: How can I add gprof profiler to my CMakeLists.txt?
On Tue, 2009-12-15 at 12:08 +0800, Water Lin wrote:
> I want to use gprof to analyze my code. So I try to embed the -pg
> paramter for g++ in my CMakeLists.txt file.
> But after I embeded the -pg to my CMakeLists.txt like this:
> add_definitions(-pg -march=pentium4 -msse3 -g)
> and I recompile my code. There is no gprof output file.
> But when I use command like:
> $ g++ -pg ....
> to compile my code, gprof will generate a output file gmon.out.
> So, how can I enable gprof profiler in my CMakeLists.txt?
> Water Lin
Hi Water Lin,
>From the g++ info files:
Generate extra code to write profile information suitable for the
analysis program `gprof'. You must use this option when compiling
the source files you want data about, and you must also use it when
So, you should use `-pg' both when compiling and linking. The command
add_definitions() will only add this option during compilation. You
should also add `-pg' to CMAKE_EXE_LINKER_FLAGS or to
CMAKE_EXE_LINKER_FLAGS_[CMAKE_BUILD_TYPE], where CMAKE_BUILD_TYPE could
be, e.g., `DEBUG'.
Powered by www.kitware.com