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? > > Thanks > > Water Lin
Hi Water Lin, >From the g++ info files: `-pg' 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 linking. 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'. HTH, Marcel Loose. _______________________________________________ Powered by www.kitware.com Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Follow this link to subscribe/unsubscribe: http://www.cmake.org/mailman/listinfo/cmake