简体   繁体   中英

Why is gcc compiler flag unknown?

Been trying to add this flag: -Wshadow=compatible-local ( documentation ) when compiling but it just keeps throwing this message:


`error: unknown warning option '-Wshadow=compatible-local';
 did you mean '-Wshadow- uncaptured-local'?
 [-Werror,-Wunknown-warning-option]`

Snippet of my makefile:

# COMPILER & FLAGS ============================================================

CC = gcc
CFLAGS = -g -std=c11 -O3 \
         -Wall -Wextra -Werror \
         -Wshadow -Wshadow=compatible-local \
         -Wno-sign-compare \
         -fsanitize=integer \
         -fsanitize=undefined \
         -fsanitize=address -fsanitize-address-use-after-scope

Updated:

Note: my compiler version is clang-900.0.39.2 . (It says clang even though you type in gcc , because I'm using macOS and well ... @Aconcagua explains why down below)


Someone know why this is happening ? and/or how to fix it ?

It seems that clang uses quite different flag naming: http://clang.llvm.org/docs/DiagnosticsReference.html#wshadow-uncaptured-local

It should be -Wshadow-uncaptured-local rather than -Wshadow=compatible-local .

Some time ago, GCC was the default compiler on MacOS, then Apple decided to switch to clang as default. Suppose they linked GCC to clang to avoid people wondering why the compiler disappeared (well, more reasonable: not to break any build systems...). Good idea? At least leading to confusion where incompatibilities come into play...

"How to fix?"

Install a true GCC on your system, replacing the symlink to clang.

If you prefer going on with clang (not a bad choice either), drop the flag that apparently is GCC-specific and not supported by clang (you can replace it with clang's equivalent, see vpetrigo 's answer ).

You even might adapt your makefile to be compatible with both: Get the compiler's version string, check if the string returned contains "gcc" or "clang" and then add the appropriate compiler flags conditionally.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM