prefer static linking

Ian Lance Taylor iant@google.com
Tue Nov 29 23:56:00 GMT 2011


"Weaver, John P CIV" <john.p.weaver@navy.mil> writes:

> The gcc compiler prefers to use dynamic libraries in the linking
> phase. When porting software from one machine to another it is
> frequently desirable to link to static libraries as much as possible
> to account for different versions of the libraries. The -static flag
> is useful when you do not need any dynamic library support but causes
> the linker to fail if there is only a dynamic library for a particular
> call. Is there a way to ask the linker to use static libraries when
> possible and report the dynamic libraries that are needed to complete
> the linking process?

I am not aware of any such option.

If you are using the GNU linker, you can tell it to prefer dynamic
libraries using -Bdynamic and tell it to use only static libraries using
-Bstatic, but I don't know of any option to tell it to prefer static
libraries but use dynamic libraries if they are available.

Ian



More information about the Gcc-help mailing list