如何在cmake中使用gprof [英] How to use gprof with cmake
问题描述
我看过许多使用gprof进行分析的教程.我正在尝试使用SMT求解器dReal的代码.为了构建程序,我首先安装了g ++-4.8,Bison,Flex和Cmake.然后要构建dReal,说明要执行以下操作:
I have looked at dozens of tutorials for profiling with gprof. I'm trying to work with code for the SMT solver dReal. To build the program, I first installed g++-4.8, Bison, Flex, and Cmake. Then to build dReal, the instructions said to execute the following:
git clone git@github.com:soonhokong/dReal.git dreal
cd dreal
mkdir -p build/release
cd build/release
cmake -DCMAKE_BUILD_TYPE=RELEASE -DCMAKE_CXX_COMPILER=g++-4.8 -DCMAKE_C_COMPILER=gcc-4.8 ../../src
make
我应该在哪里添加-pg
?我是编程的新手,因此非常乐于推理而不是答案.我知道您应该在编译阶段添加-pg
,但是所有教程都说应将其放在g ++或gcc之后.我找不到如何修改cmake的代码.我确实尝试将构建类型更改为PROFILE,但这没有帮助.
Where in here am I supposed to add the -pg
? I'm new to programming, so reasoning as opposed to an answer would be much appreciated. I know you're supposed to add the -pg
to the compilation stage but all the tutorials say to put it after g++ or gcc. I can't find how to modify the code for cmake. I did try changing the build type to PROFILE but that didn't help.
推荐答案
要使用gprof,您需要同时编译和链接-pg
选项.
In order to use gprof, you need to both compile and link with the -pg
option.
CMakeLists.txt应该具有提到的Ami Tavory这样的设置,其中命令行选项与硬编码选项结合在一起,因此,对构建良好的cmake项目执行此操作的一种好方法是:
CMakeLists.txt should have a setup like Ami Tavory mentioned, where command line options are combined with hardcoded options, so a good way to do this with a well built cmake project is:
cmake -DCMAKE_CXX_FLAGS=-pg -DCMAKE_EXE_LINKER_FLAGS=-pg -DCMAKE_SHARED_LINKER_FLAGS=-pg <SOURCE_DIR>
这篇关于如何在cmake中使用gprof的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!