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

问题描述 投票:0回答:1

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

$ 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");        
}

没有-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 cygwin gprof
1个回答
1
投票

来自gcc信息页面

'-pg' 生成额外的代码以编写适合分析程序'gprof'的配置文件信息。编译所需数据的源文件时必须使用此选项,并且在链接时也必须使用它。

因此,如果你想进行单独的编译和链接,你需要重复qazxsw poi

-pg
© www.soinside.com 2019 - 2024. All rights reserved.