gpt4 book ai didi

c++ - -pg 标志不产生 gmon.out 文件

转载 作者:太空宇宙 更新时间:2023-11-04 13:05:58 30 4
gpt4 key购买 nike

我使用 -pg 标志编译和链接我的 cpp 程序,运行该程序,并检查我的目录中是否有 gmon.out。我找不到任何东西。

我正在运行 Ubuntu 16.04 LTS,这是一个完全默认的 codelite 项目。唯一的事情是我将 -pg 标志添加到 c++ 编译选项和链接选项。

我已经阅读了所有询问相同问题的其他线程。我相信我的问题有所不同。

这是我的生成文件:

##
## Auto Generated makefile by CodeLite IDE
## any manual changes will be erased
##
## Release
ProjectName :=trying_reproducible_gprof_error
ConfigurationName :=Release
WorkspacePath :=/home/taylor/Documents/ssmworkspace
ProjectPath :=/home/taylor/Documents/ssmworkspace/trying_reproducible_gprof_error
IntermediateDirectory :=./Release
OutDir := $(IntermediateDirectory)
CurrentFileName :=
CurrentFilePath :=
CurrentFileFullPath :=
User :=taylor
Date :=20/02/17
CodeLitePath :=/home/taylor/.codelite
LinkerName :=/usr/bin/g++
SharedObjectLinkerName :=/usr/bin/g++ -shared -fPIC
ObjectSuffix :=.o
DependSuffix :=.o.d
PreprocessSuffix :=.i
DebugSwitch :=-g
IncludeSwitch :=-I
LibrarySwitch :=-l
OutputSwitch :=-o
LibraryPathSwitch :=-L
PreprocessorSwitch :=-D
SourceSwitch :=-c
OutputFile :=$(IntermediateDirectory)/$(ProjectName)
Preprocessors :=$(PreprocessorSwitch)NDEBUG
ObjectSwitch :=-o
ArchiveOutputSwitch :=
PreprocessOnlySwitch :=-E
ObjectsFileList :="trying_reproducible_gprof_error.txt"
PCHCompileFlags :=
MakeDirCommand :=mkdir -p
LinkOptions := -pg
IncludePath := $(IncludeSwitch). $(IncludeSwitch).
IncludePCH :=
RcIncludePath :=
Libs :=
ArLibs :=
LibPath := $(LibraryPathSwitch).

##
## Common variables
## AR, CXX, CC, AS, CXXFLAGS and CFLAGS can be overriden using an environment variables
##
AR := /usr/bin/ar rcu
CXX := /usr/bin/g++
CC := /usr/bin/gcc
CXXFLAGS := -pg -O2 -Wall $(Preprocessors)
CFLAGS := -O2 -Wall $(Preprocessors)
ASFLAGS :=
AS := /usr/bin/as


##
## User defined environment variables
##
CodeLiteDir:=/usr/share/codelite
Objects0=$(IntermediateDirectory)/main.cpp$(ObjectSuffix)



Objects=$(Objects0)

##
## Main Build Targets
##
.PHONY: all clean PreBuild PrePreBuild PostBuild MakeIntermediateDirs
all: $(OutputFile)

$(OutputFile): $(IntermediateDirectory)/.d $(Objects)
@$(MakeDirCommand) $(@D)
@echo "" > $(IntermediateDirectory)/.d
@echo $(Objects0) > $(ObjectsFileList)
$(LinkerName) $(OutputSwitch)$(OutputFile) @$(ObjectsFileList) $(LibPath) $(Libs) $(LinkOptions)

MakeIntermediateDirs:
@test -d ./Release || $(MakeDirCommand) ./Release


$(IntermediateDirectory)/.d:
@test -d ./Release || $(MakeDirCommand) ./Release

PreBuild:


##
## Objects
##
$(IntermediateDirectory)/main.cpp$(ObjectSuffix): main.cpp $(IntermediateDirectory)/main.cpp$(DependSuffix)
$(CXX) $(IncludePCH) $(SourceSwitch) "/home/taylor/Documents/ssmworkspace/trying_reproducible_gprof_error/main.cpp" $(CXXFLAGS) $(ObjectSwitch)$(IntermediateDirectory)/main.cpp$(ObjectSuffix) $(IncludePath)
$(IntermediateDirectory)/main.cpp$(DependSuffix): main.cpp
@$(CXX) $(CXXFLAGS) $(IncludePCH) $(IncludePath) -MG -MP -MT$(IntermediateDirectory)/main.cpp$(ObjectSuffix) -MF$(IntermediateDirectory)/main.cpp$(DependSuffix) -MM main.cpp

$(IntermediateDirectory)/main.cpp$(PreprocessSuffix): main.cpp
$(CXX) $(CXXFLAGS) $(IncludePCH) $(IncludePath) $(PreprocessOnlySwitch) $(OutputSwitch) $(IntermediateDirectory)/main.cpp$(PreprocessSuffix) main.cpp


-include $(IntermediateDirectory)/*$(DependSuffix)
##
## Clean
##
clean:
$(RM) -r ./Release/

这是项目中唯一的文件,main.cpp:

#include <stdio.h>

int main(int argc, char **argv)
{
printf("hello world\n");
return 0;
}

编辑:

我将 main.cpp 更改为以下内容,现在它可以工作了:

#include <iostream>

void printLol(){
std::cout << "lol........\n";
}

int main(int argc, char **argv)
{
std::cout << "hello world\n";
for(int i = 0; i < 10; ++i)
printLol();

return 0;
}

要么我至少需要一个非主函数,要么 gprof 不喜欢 stdio.h。如果愿意,任何人都可以试着解释一下。

最佳答案

Gprof 是一个基于采样的分析器,您的第一个示例应用程序的执行量太小,无法被 Gprof 注册。

尝试在应用程序中添加一些 sleep(1) 调用,然后再试一次。

关于c++ - -pg 标志不产生 gmon.out 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42358059/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com