views:

249

answers:

2

Or does it just make more sense to leave the optimization until you use the library, or is it when you link the library you are already past the point where the compiler can optimize the library?

+1  A: 

If you want the code in the library optimised, you have to provide the optimisation flags when you compile the library, not when you link with it.

anon
some of the gnu documentation suggests that you can get optimizations at link time too, which is what confuses me
ldog
@gmatt The linker may be able to perform some very specialised optimisations, but the main ones (things like loop unrolling) need to be performed at compile time.
anon
+2  A: 

Code optimization happens primarily at compile time. So if you want your static library optimized, you need to do that when you build your library.

There are some optimizations that can happen at link time (although I'm not sure if the GNU linker implements them). But they are additional optimizations, so even if you wanted to use them, you would still want to compile time optimization.

R Samuel Klatchko