AymenTM
AymenTM

Reputation: 569

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 ?

Upvotes: 0

Views: 1969

Answers (2)

Aconcagua
Aconcagua

Reputation: 25536

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.

Upvotes: 2

vpetrigo
vpetrigo

Reputation: 325

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.

Upvotes: 5

Related Questions