gpt4 book ai didi

gcc - 如何在cygwin中将-pg传递给gcc

转载 作者:行者123 更新时间:2023-12-05 03:01:45 26 4
gpt4 key购买 nike

我只是想测试-pg,源文件很简单,我的环境是赛格文,

$ uname -a 
CYGWIN_NT-10.0 SHA-LPLATOW 2.8.2(0.313/5/3) 2017-07-12 10:58 x86_64 Cygwin

$ vi pgtest.c

#include <stdio.h>
void main(void){
printf("hello, world\n");
}

no -pg 编译成功

$ gcc -c pgtest.c
$ gcc -o pgtest.exe pgtest.o

但是-pg报错

$ gcc -pg -c pgtest.c
$ gcc -o pgtest.exe pgtest.o
pgtest.o:pgtest.c:(.text+0x1): undefined reference to `__fentry__'
pgtest.o:pgtest.c:(.text+0x1): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `__fentry__'
pgtest.o:pgtest.c:(.text+0xe): undefined reference to `_monstartup'
pgtest.o:pgtest.c:(.text+0xe): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `_monstartup'
collect2: error: ld returned 1 exit status

我试过LDFLAGS,都是一样的。

export LDFLAGS="-pg" ; gcc -o pgtest.exe pgtest.o

最佳答案

来自 gcc 信息页面

'-pg'
Generate extra code to write profile information suitable for the analysis program 'gprof'. You must use this option when compiling the source files you want data about, and you must also use it when linking.

所以如果你想做一个单独的编译和链接你需要重复-pg

$ gcc -c pgtest.c -pg
$ gcc -o pgtest.exe pgtest.o -pg

关于gcc - 如何在cygwin中将-pg传递给gcc,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55566393/

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