本文介绍了如何设置g ++使用cmake的标志,使gprof可以解构?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在CMakeLists.txt中为GNU g ++的编译器和链接器设置gprof标志?
我目前的方法,
设定(CMAKE_C_FLAGS_RELWITHDEBINFO$ {CMAKE_C_FLAGS_RELWITHDEBINFO } -pg)
pre>
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO$ {CMAKE_CXX_FLAGS_RELWITHDEBINFO} -pg)
set(CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO$ {CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO} -pg)
不允许gprof解析C ++函数。有任何想法吗? (我使用C ++ 11)
解决方案尝试使用:
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)
必须添加标志来编译和链接,
gprof ./my_exe
如果您遇到以下错误:
gmon.out:没有这样的文件或目录
这意味着编译没有正确添加分析信息。
这里的一系列事件应该工作如下:
1º使用-pg选项编译代码
2º链接代码与-pg选项
3º运行程序
4º程序生成gmon.out文件
5º运行gprof
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)
解决方案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
这篇关于如何设置g ++使用cmake的标志,使gprof可以解构?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!