Reputation: 1195
I am trying to compile a opensource component from source code. I am compiling all C files in that component using gcc
command.
When I pass options in order -O2 -Os
, binary is in few KB's. But when I pass options in order -Os -O2
binary size is large.
I do know that order matter in case of including sub-directories or Linking libraries in gcc
command.
Why order matters for optimization arguments of gcc
command ?
I am using gcc version 4.9.1.
Upvotes: 1
Views: 169
Reputation: 146211
Because it's just using the last1 option it sees.
1. From the man page: If you use multiple -O options, with or without level numbers, the last such option is the one that is effective.
Upvotes: 1
Reputation: 206861
From the GCC man page:
If you use multiple
-O
options, with or without level numbers, the last such option is the one that is effective.
You can't combine -O2
and -Os
on the command line.
But here's the description of -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.
Looks like -Os
is already doing what you want.
Upvotes: 1