Earlier I was compiling the coreutils application on CentOS Linux and ran into an issue after using the “make” command. At first I was confused because I wasn’t doing anything complex but then I realized that I had simply mistyped an environment variable I had previously set. Below I describe the actual error, what was mistyped, and how I resolved the problem.
Linux make Error: gcc: unrecognized option ‘-02’
- gcc: unrecognized option '-02'
- CC base64.o
- gcc: unrecognized option '-02'
- CC c-ctype.o
- gcc: unrecognized option '-02'
- CC c-strcasecmp.o
- gcc: unrecognized option '-02'
- CC c-strncasecmp.o
- gcc: unrecognized option '-02'
- CC close-hook.o
- gcc: unrecognized option '-02'
- CC diacrit.o
- gcc: unrecognized option '-02'
- CC file-set.o
- gcc: unrecognized option '-02'
- CC filevercmp.o
- gcc: unrecognized option '-02'
- CC freadahead.o
Above is part of the output after using the make command with the coreutils source on CentOS Linux. I realized that prior to issuing the make command I had typed in the below environment variable.
Incorrect CFLAGS Environment Variable Set:
- export CFLAGS="-static -02 -g"
It wasn’t easy to recognize at first however I finally realized that I had set -02 (zero two) instead of -O2 (o for optimize two). This caused an error since -02 is not a possible switch with gcc. So instead I should have set the below CFLAGS environment variable.
Correct CFLAGS Environment Variable Set:
- export CFLAGS="-static -O2 -g"
Once this environment variable was set properly I no longer received the error. Also to expand on what was being set I was setting two gcc switches which are mentioned below from the gcc man page.
GCC -static and -O2 Switches:
- -static
- On systems that support dynamic linking, this prevents linking with the shared libraries. On other systems, this option has no effect.
- -O
- -O1 Optimize. Optimizing compilation takes somewhat more time, and a lot more memory for a large function.
- With -O, the compiler tries to reduce code size and execution time, without performing any optimizations that take a great deal of compilation time.
- -O turns on the following optimization flags: -fdefer-pop -fdelayed-branch -fguess-branch-probability -fcprop-registers -floop-optimize -fif-conversion -fif-conversion2 -ftree-ccp -ftree-dce -ftree-dominator-opts -ftree-dse -ftree-ter -ftree-lrs -ftree-sra -ftree-copyrename -ftree-fre -ftree-ch-funit-at-a-time -fmerge-constants
- -O also turns on -fomit-frame-pointer on machines where doing so does not interfere with debugging.
- -O doesn't turn on -ftree-sra for the Ada compiler. This option must be explicitly specified on the command line to be enabled for the Ada compiler.
- -O2 Optimize even more. GCC performs nearly all supported optimizations that do not involve a space-speed tradeoff. The compiler does not perform loop unrolling or function inlining when you specify -O2. As compared to -O, this option increases both compilation time and the performance of the generated code.
- -O doesn't turn on -ftree-sra for the Ada compiler. This option must be explicitly specified on the command line to be enabled for the Ada compiler.
- -O2 Optimize even more. GCC performs nearly all supported optimizations that do not involve a space-speed tradeoff. The compiler does not perform loop unrolling or function inlining when you specify -O2. As compared to -O, this option increases both compilation time and the performance of the generated code.
- -O2 turns on all optimization flags specified by -O. It also turns on the following optimization flags: -fthread-jumps -fcrossjumping -foptimize-sibling-calls -fcse-follow-jumps -fcse-skip-blocks -fgcse-fgcse-lm -fexpensive-optimizations -fstrength-reduce -frerun-cse-after-loop -frerun-loop-opt-fcaller-saves -fpeephole2 -fschedule-insns -fschedule-insns2 -fsched-interblock -fsched-spec -fregmove-fstrict-aliasing -fdelete-null-pointer-checks -freorder-blocks -freorder-functions -falign-functions -falign-jumps -falign-loops -falign-labels -ftree-vrp -ftree-pre
- Please note the warning under -fgcse about invoking -O2 on programs that use computed gotos.
- -O3 Optimize yet more. -O3 turns on all optimizations specified by -O2 and also turns on the -finline-functions, -funswitch-loops and -fgcse-after-reload options.
- -O0 Do not optimize. This is the default.
- -Os Optimize for size. -Os enables all -O2 optimizations that do not typically increase code size. It also performs further optimizations designed to reduce code size.
- -Os disables the following optimization flags: -falign-functions -falign-jumps -falign-loops -falign-labels -freorder-blocks -freorder-blocks-and-partition -fprefetch-loop-arrays -ftree-vect-loop-version
- If you use multiple -O options, with or without level numbers, the last such option is the one that is effective.
- Options of the form -fflag specify machine-independent flags. Most flags have both positive and negative forms; the negative form of -ffoo would be -fno-foo. In the table below, only one of the forms is listed---the one you typically will use. You can figure out the other form by either removing no- or adding it.
- The following options control specific optimizations. They are either activated by -O options or are related to ones that are. You can use the following flags in the rare cases when "fine-tuning" of optimizations to be performed is desired.
So we had set the optimize (level 2) switch as well as the static switch.