public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* prefer static linking
@ 2011-11-29 23:47 Weaver, John P CIV
  2011-11-29 23:56 ` Ian Lance Taylor
  0 siblings, 1 reply; 3+ messages in thread
From: Weaver, John P CIV @ 2011-11-29 23:47 UTC (permalink / raw)
  To: gcc-help

[-- Attachment #1: Type: text/plain, Size: 654 bytes --]

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?

Patrick Weaver
China Lake, CA
Voice: (760) 939-8744
Email: john.p.weaver(at)navy.mil



[-- Attachment #2: smime.p7s --]
[-- Type: application/x-pkcs7-signature, Size: 5672 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: prefer static linking
  2011-11-29 23:47 prefer static linking Weaver, John P CIV
@ 2011-11-29 23:56 ` Ian Lance Taylor
  2011-11-30  1:29   ` Weaver, John P CIV
  0 siblings, 1 reply; 3+ messages in thread
From: Ian Lance Taylor @ 2011-11-29 23:56 UTC (permalink / raw)
  To: Weaver, John P CIV; +Cc: gcc-help

"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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* RE: prefer static linking
  2011-11-29 23:56 ` Ian Lance Taylor
@ 2011-11-30  1:29   ` Weaver, John P CIV
  0 siblings, 0 replies; 3+ messages in thread
From: Weaver, John P CIV @ 2011-11-30  1:29 UTC (permalink / raw)
  To: Ian Lance Taylor, Jonathan Wakely; +Cc: gcc-help

Following the chain and playing around with the makefile has yielded the
following, judicious use of both -Bdynamic and -Bstatic in front of the
different -l statements does in fact change the behavior of the linker
so that the desired outcome is achieved. Thank you both for your input.

Patrick Weaver
China Lake, CA
Voice: (760) 939-8744
Email: john.p.weaver(at)navy.mil

-----Original Message-----
From: Jonathan Wakely [mailto:jwakely.gcc@gmail.com] 
Sent: Tuesday, November 29, 2011 11:29
To: Weaver, John P CIV
Cc: gcc-help@gcc.gnu.org
Subject: Re: prefer static linking


On Nov 29, 2011 7:03 PM, "Weaver, John P CIV" wrote:
>
> The gcc compiler prefers to use dynamic libraries in the linking
phase.

GCC just calls the linker, any preference is the linker's.

For the GNU linker -Bdynamic and -Bstatic allow you to control whether
dynamic or static libraries are used for each lib named with -l 

See 'man ld'

-----Original Message-----
From: Ian Lance Taylor [mailto:iant@google.com] 
Sent: Tuesday, November 29, 2011 11:21
To: Weaver, John P CIV
Cc: gcc-help@gcc.gnu.org
Subject: Re: prefer static linking

"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

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2011-11-29 20:21 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-11-29 23:47 prefer static linking Weaver, John P CIV
2011-11-29 23:56 ` Ian Lance Taylor
2011-11-30  1:29   ` Weaver, John P CIV

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).