public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* Static and Dynamic Linking with GCC
@ 2001-07-20 14:27 Dan Mergens
  2001-07-20 14:42 ` H . J . Lu
  2001-07-20 14:43 ` Phil Edwards
  0 siblings, 2 replies; 3+ messages in thread
From: Dan Mergens @ 2001-07-20 14:27 UTC (permalink / raw)
  To: gcc

Is it possible to link with both static and dynamic libraries on a gcc
compile line? The -static option prevents dynamic linking, and in
version 3 you can choose the link mode for libgcc. However, I want to
know if I can specify the libraries to be link statically or
dynamically. For example, in IRIX you can do the following:

CC a.o -B static -lfoo -Bdynamic -lbar

which will link which libfoo.a, libbar.so, and the standard .so's

What is the equivalent gcc command line? (I'm beginning to think it
doesn't exist).

Thanks!
Dan Mergens

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

* Re: Static and Dynamic Linking with GCC
  2001-07-20 14:27 Static and Dynamic Linking with GCC Dan Mergens
@ 2001-07-20 14:42 ` H . J . Lu
  2001-07-20 14:43 ` Phil Edwards
  1 sibling, 0 replies; 3+ messages in thread
From: H . J . Lu @ 2001-07-20 14:42 UTC (permalink / raw)
  To: Dan Mergens; +Cc: gcc

On Fri, Jul 20, 2001 at 02:27:08PM -0700, Dan Mergens wrote:
> Is it possible to link with both static and dynamic libraries on a gcc
> compile line? The -static option prevents dynamic linking, and in
> version 3 you can choose the link mode for libgcc. However, I want to
> know if I can specify the libraries to be link statically or
> dynamically. For example, in IRIX you can do the following:
> 
> CC a.o -B static -lfoo -Bdynamic -lbar
> 
> which will link which libfoo.a, libbar.so, and the standard .so's

Assuming you are using the GNU binutils, do

# gcc a.o -Wl,-Bstatic -lfoo -Wl,-Bdynamic -lbar


H.J.

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

* Re: Static and Dynamic Linking with GCC
  2001-07-20 14:27 Static and Dynamic Linking with GCC Dan Mergens
  2001-07-20 14:42 ` H . J . Lu
@ 2001-07-20 14:43 ` Phil Edwards
  1 sibling, 0 replies; 3+ messages in thread
From: Phil Edwards @ 2001-07-20 14:43 UTC (permalink / raw)
  To: Dan Mergens; +Cc: gcc

On Fri, Jul 20, 2001 at 02:27:08PM -0700, Dan Mergens wrote:
> For example, in IRIX you can do the following:
> 
> CC a.o -B static -lfoo -Bdynamic -lbar
> 
> which will link which libfoo.a, libbar.so, and the standard .so's
> 
> What is the equivalent gcc command line? (I'm beginning to think it
> doesn't exist).

This is largely (and on many platforms, entirely) a function of the
linker, not the compiler per se.  The compiler driver ("gcc" or "g++",
etc) can pass arbitrary (comma-separated) options to the linker with -Wl,
so you need to read the man page for the linker you're using[*], figure out
which options to pass to it, and then feed those to gcc/g++.  For example,
on Solaris it's something like

    gcc a.o b.o ... z.o -Wl,-B,static -lfoo -Wl,-B,dynamic -lbar

and the linker receives

    ld ..... -B static -lfoo -B dynamic -lbar ....


Phil
[*] Run 'gcc --print-prog-name=ld' to get the full path to ld; then you
    can investigate that binary and determine which one is in use.

-- 
Would I had phrases that are not known, utterances that are strange, in
new language that has not been used, free from repetition, not an utterance
which has grown stale, which men of old have spoken.
                                     - anonymous Egyptian scribe, c.1700 BC

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

end of thread, other threads:[~2001-07-20 14:43 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-07-20 14:27 Static and Dynamic Linking with GCC Dan Mergens
2001-07-20 14:42 ` H . J . Lu
2001-07-20 14:43 ` Phil Edwards

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).