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

蹲街弑〆低调 提交于 2019-12-07 02:36:01

问题


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)


回答1:


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


来源:https://stackoverflow.com/questions/23560214/how-to-set-flags-of-g-using-cmake-such-that-gprof-can-demangle

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!