Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set flags of g++ using cmake such that gprof can demangle?

How do I set the gprof flags for the compiler and linker of GNU g++ in a CMakeLists.txt?

My current approach,

set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO} -pg")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -pg")
set(CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO} -pg")

does not allow gprof to demangle the C++ functions. Any ideas? (I am using C++11)

like image 542
Max Flow Avatar asked May 09 '14 08:05

Max Flow


1 Answers

Try using:

SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pg")
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pg")
SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -pg")

That must add flags to compile and link, and use after execute the program:

gprof ./my_exe

If you get an error like:

gmon.out: No such file or directory

That means that compilation didn't add profiling info propertly.

The series of events here is supposed to work as follows:

1º Compile code with -pg option
2º Link code with -pg option
3º Run program
4º Program generates gmon.out file
5º Run gprof
like image 109
vgonisanz Avatar answered Oct 14 '22 16:10

vgonisanz