steviekm3
steviekm3

Reputation: 1053

Possible to link together libraries into one library, and resolve internal function calls?

I am working on a system with hundreds of excecutables. Each executable fully links in various .a libraries statically. Shared libraries are not an option right now. A fully rebuild is quite slow. Bottle neck seems to be linking since each executable has to be relinked and there are hundreds.

Is it possible to create a "master" library of all the libraries where internal function calls are resolved, then use this master library when linking the binaries ? The idea being that time would be saved due to internal library calls already being resolved. ( there are many calls between the libraries ).

We do not use clang and I don't believe incremental linking is an option.

Upvotes: 0

Views: 30

Answers (1)

Employed Russian
Employed Russian

Reputation: 213754

Is it possible to create a "master" library

Sure: ld -r -o master.o --whole-archive libfoo.a libbar.a ... should do it.

There is a high chance that each of your binaries will become larger (explanation).

Also, if you are using ELF, you may get significantly faster links using the (new) Gold linker.

Finally, if you are building on a powerful machine with lots of RAM (as you should), running make -j12 or even higher should speed things up considerably by executing many links in parallel. This requires correct Makefile structure and correct dependencies (which you should have anyway for correctness of your builds).

Upvotes: 2

Related Questions