[CMake] Programs linked to .a or .so libraries?

Hendrik Sattler post at hendrik-sattler.de
Tue Aug 28 09:49:08 EDT 2007


Am Dienstag 28 August 2007 14:54 schrieb Philip Lowman:
> Hendrik Sattler wrote:
> > Am Dienstag 28 August 2007 12:31 schrieb Convey Christian J NPRI:
> >> Thanks for the info.  What a strange feature for CMake to lack!  Does
> >> anyone know why this hasn't been implemented?
> >
> > OTOH, did you ask yourself why you actually want static linking? Sure,
> > your program will run that way but only with increased memory usage and
> > load time. It's not a good thing to do (that's what APIs and ABIs are
> > for). If the linker on a system prefers dynamic linking, why do you want
> > to override it?
>
> I've never read that shared libraries are faster than static
> executables.  One would think that, if anything, all of the hoops the OS
> has to run through to map all of the symbols would cause applications
> that use shared libraries to be slower to startup then statically built
> executables.

But there are big libs once in a while that need some time to load itself.
Just imagine static version of skype that uses QT. In an environment that also 
uses those libs, e.g. KDE, the startup time for the application is extremely 
slow. Personal experience, here.
And you also have a disk buffer, so that with two different applications, that 
do share a library but do not run at the same time, gain from using a shared 
library.

> As for system memory, a static executable will only use more system
> memory if it's using code that other programs are also using at the same
> time (libgtk, libxml, etc.).  In that case (and that case only) you
> would have multiple programs loading the same symbols into memory and
> thus would be wasting system memory.

Well, a statically linked program may even consume less memory (and may load 
faster) if it only uses a subset of a library and the linker does it right. 
However, with more than one program, the chances go down very fast that 
static linking is a good choice.

But it's also a security nightmare: you cannot just update the lib, you also 
have to relink the program.

HS


More information about the CMake mailing list