On Ubuntu with g++4.9, I have built a static library (call it libZeroMQ.a) following its instructions, and it was built without "-flto" (link time optimization).
Now I am working on a project (call it MyEXE) which uses libZeroMQ.a, and I'll statically link all libraries. I wish to build MyEXE with LTO.
I have two options:
A) Build MyEXE, using "-flto" in both compiling and linking. Link with the previously built libZeroMQ.a.
B) Hack(change) ZeroMQ's config/build scripts, add "-flto", and rebuild libZeroMQ.a. Then build MyEXE by linking with the new libZeroMQ.a. Of course, still using "-flto" in both compiling and linking MyEXE.
In terms of performance of MyEXE, I think:
B) is better than A) because it allows more code (specifically, code in ZeroMQ) to be considered for optimisation at link time.
A) is still better than not using LTO at all.
Is my understanding correct? Thanks!
I am really struggling with making this an answer rather than a comment, but it is an answer:
Yes, your understanding is correct.