* Static Linking and Library Dependencies
@ 2006-07-17 14:50 Browder, Tom
2006-07-18 9:44 ` Nick Clifton
0 siblings, 1 reply; 4+ messages in thread
From: Browder, Tom @ 2006-07-17 14:50 UTC (permalink / raw)
To: binutils
Say I have two static libraries A and B.
In A there is only one function, foo, that depends upon B.
My program uses functions in A other than foo.
Is there any way to link my program with A but not have to link B also?
Thanks.
-Tom
Tom Browder
Nicevile, FL
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Static Linking and Library Dependencies
2006-07-17 14:50 Static Linking and Library Dependencies Browder, Tom
@ 2006-07-18 9:44 ` Nick Clifton
2006-07-18 15:25 ` Browder, Tom
0 siblings, 1 reply; 4+ messages in thread
From: Nick Clifton @ 2006-07-18 9:44 UTC (permalink / raw)
To: Browder, Tom; +Cc: binutils
Hi Tom,
> Say I have two static libraries A and B.
> In A there is only one function, foo, that depends upon B.
> My program uses functions in A other than foo.
> Is there any way to link my program with A but not have to link B also?
Yes.
I am tempted to just leave the answer there, but I will be nice. If the
other functions in A which are used by your program are in different
object files within the library then B will not be linked it at all, and
you will not have to do any extra work.
If there are functions in A which are used by your program and which are
in the same file(*) as foo then you have two choices. If you have
access to the sources for A then you can recompile it with the
-ffunction-sections switch and then link with the --gc-sections switch.
This should allow foo and its dependencies in B to be discarded by the
linker. (Alternatively you can hand edit the sources for A so that foo
is compiled in its own file).
If you do not have the sources for A then you can create a dummy version
of the B library that is empty apart from the symbols needed to satisfy
the references in foo(). Then you can use this dummy library in place
of B. This solution is not as elegant but it should work.
Cheers
Nick
(*) Strictly speaking I should be talking about "compilation units" here
rather than "files".
^ permalink raw reply [flat|nested] 4+ messages in thread
* RE: Static Linking and Library Dependencies
2006-07-18 9:44 ` Nick Clifton
@ 2006-07-18 15:25 ` Browder, Tom
2006-07-18 15:29 ` Eric Christopher
0 siblings, 1 reply; 4+ messages in thread
From: Browder, Tom @ 2006-07-18 15:25 UTC (permalink / raw)
To: Nick Clifton; +Cc: binutils
> -----Original Message-----
> From: Nick Clifton [mailto:nickc@redhat.com]
...
> Yes.
>
> I am tempted to just leave the answer there, but I will be
> nice. If the other functions in A which are used by your
Thanks, Nick, that's very helpful.
The problem for me has been that the intimate details of linking and
loading are scattered in pieces all around the net. The GNU manuals on
gcc, ar, ld, and libtool help but most of them assume knowledge that the
reader may not have who just happily does "./configure; make; make
install." Ulrich Drepper's papers also help, but again dive too deeply
for me too quickly.
I would be happy to buy a good textbook on the subject if you have a
suggestion.
Thanks again.
-Tom
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Static Linking and Library Dependencies
2006-07-18 15:25 ` Browder, Tom
@ 2006-07-18 15:29 ` Eric Christopher
0 siblings, 0 replies; 4+ messages in thread
From: Eric Christopher @ 2006-07-18 15:29 UTC (permalink / raw)
To: Browder, Tom; +Cc: binutils
> I would be happy to buy a good textbook on the subject if you have a
> suggestion.
>
Textbooks for this are in short supply :)
About the only suggestion would be "Linkers and Loaders":
http://www.amazon.com/gp/product/1558604960/sr=8-1/qid=1153236559/ref=pd_bbs_1/103-9595114-2289464?ie=UTF8
-eric
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2006-07-18 15:29 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-07-17 14:50 Static Linking and Library Dependencies Browder, Tom
2006-07-18 9:44 ` Nick Clifton
2006-07-18 15:25 ` Browder, Tom
2006-07-18 15:29 ` Eric Christopher
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).