gpt4 book ai didi

无法让 makefile 生成 gmon.out

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

我正在尝试分析我的代码,因为我不知道是什么导致它变慢了。我有以下生成文件:

CXX=gcc
RM=rm -f
CFLAGS=-pg -DNDEBUG -O3 -g3 -O0 -D_FILE_OFFSET_BITS=64
LDFLAGS=-pg -lpthread `pkg-config fuse --cflags --libs`
EXEC = fs

SRCS=$(shell echo *.c)
OBJS=$(subst .c,.o,$(SRCS))

all: $(EXEC)

$(EXEC): $(OBJS)
$(CXX) $(LDFLAGS) -o $(EXEC) $(OBJS)

%.o: %.c
$(CXX) $(CFLAGS) -c -o $@ $^

clean:
$(RM) *.o
$(RM) $(EXEC)

产生这个输出:

gcc -pg -DNDEBUG -O3 -g3 -O0 -D_FILE_OFFSET_BITS=64 -c -o datablock.o datablock.c
gcc -pg -DNDEBUG -O3 -g3 -O0 -D_FILE_OFFSET_BITS=64 -c -o disk.o disk.c
gcc -pg -DNDEBUG -O3 -g3 -O0 -D_FILE_OFFSET_BITS=64 -c -o fsinterface.o fsinterface.c
gcc -pg -DNDEBUG -O3 -g3 -O0 -D_FILE_OFFSET_BITS=64 -c -o inode.o inode.c
gcc -pg -DNDEBUG -O3 -g3 -O0 -D_FILE_OFFSET_BITS=64 -c -o main.o main.c
main.c:19: warning: initialization from incompatible pointer type
gcc -pg -DNDEBUG -O3 -g3 -O0 -D_FILE_OFFSET_BITS=64 -c -o mkfs.o mkfs.c
gcc -pg -lpthread `pkg-config fuse --cflags --libs` -o fs datablock.o disk.o fsinterface.o inode.o main.o mkfs.o
[root@ip-10-2-176-50 fusefilesystemclean]# gprof fs
gmon.out: No such file or directory

而且我似乎无法生成 gmon.out 文件。我不太擅长 Makefile。有人可以帮助我吗?

谢谢。

最佳答案

在您运行您的程序之前,不会创建 gmon.out 文件。

-pg 开关只是在程序运行时添加创建 gmon.out 文件的调用。

运行你的程序:

fs

然后运行 ​​gprof:

gprof 

阅读 gprof 的手册页

关于无法让 makefile 生成 gmon.out,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20307899/

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