![Ubuntu 18.04 中的 gcc 错误](https://linux22.com/image/901758/Ubuntu%2018.04%20%E4%B8%AD%E7%9A%84%20gcc%20%E9%94%99%E8%AF%AF.png)
我尝试使用 gcc 和-mnop-mcount
选项编译 hello.c。但出现如下错误:
$ gcc -pg -mfentry -mnop-mcount -o hello hello.c
cc1: error: -mnop-mcount is not implemented for -fPIC
我的gcc版本是7.3.0:
$ gcc --version
gcc (Ubuntu 7.3.0-16ubuntu3) 7.3.0
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
我的 Ubuntu 版本是 18.04 LTS:
$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 18.04 LTS
Release: 18.04
Codename: bionic
答案1
gcc6 及更高版本默认生成fpic
代码,因为它在 ubuntu 中的编译方式。要禁用此行为,请使用fno-pic
以下标志:
gcc -pg -mfentry -mnop-mcount -fno-pic -o hello hello.c