-1

I ran into this while studying a line of code in cmake for building a library:

-Wall -Wfloat-equal -o3 -fPIC

What do these compiler flags mean and how do they work? Why do they need to be inserted?

Salek
  • 449
  • 1
  • 10
  • 19
  • [gcc option summary](https://gcc.gnu.org/onlinedocs/gcc/Option-Summary.html#Option-Summary) It's probably `-O3` not `-o3`. – KamilCuk Jan 30 '19 at 06:50
  • Or simply `man gcc`. and it is `-O3` (capital 'Oh') not `-o3`. – David C. Rankin Jan 30 '19 at 06:51
  • 1
    (the short version is `-Wall`, enable the compiler warnings listed in the `-Wall` set of warnings, `-Wfloat-equal`, warn if floating point numbers used in an equality, `-O3` enable most optimizations (`-Ofast` provides a few more)). For all questions like this, if you are going to do anything technical, you simply have to "Look it Up". – David C. Rankin Jan 30 '19 at 07:01

1 Answers1

1

-Wall -Wfloat-equal -o3 -fPIC"

So

-Wall

Enables apparently not all, but an awful lot of compiler warning messages. It should be used to generate better code since you'll know if anything's wrong.

-Wfloat-equal

Warns if floating point numbers are used in equality comparisons. Comparing floats for equality is risky business because 1.0 isn't necessarily the exact value. I'm not sure why you'd want it in this context, because it seems like -Wall would display the warnings anyways.

-o3

Is probably O3, or optimization level 3. AKA optimize to the maximum level permitted (iirc).

-fPIC

Will generate position independent code. This is a bit more complicated, but was asked before, but is useful for including in a library.

Daniel
  • 854
  • 7
  • 18