relative ordering of static libraries

K

kooladi

While linking libraries with the final binary, does the relative
ordering of libraries matter? specially for static libraries...

Lets say a.out is being complied with a1.o a2.o a3.o and linked with
lib1.a and lib2.a

a1.o contains a reference to a function resolved within lib1.a
lib2.a also contains a reference to a different function also resolved
within lib1.a.

Now, if the order the libraries as linked is lib1.a & then lib2.a , I
get an implicit dependency error. My guess is that the linker searches
within lib1.a to resolve the unresolved symbol in a1.o. When it is
done resolving, it discards the other functions within lib1.a as it
does not want to bloat the binary with functions it thinks as "un-
necessary".

However, the lib2.a library also contains an un-resolved function
which the linker now has no way of resolving. The only way is to
either reverse their ordering i.e. link lib2.a and then lib1.a or
include lib1.a again i.e lib1.a lib2.a lib1.a

Is my understanding correct ?

What are the other scenarios where the relative ordering of libraries
matter.
 
C

Chris Torek

While linking libraries with the final binary, does the relative
ordering of libraries matter?
[various examples deleted]

Yes, on systems A, B, and C; no, on systems D, E, and F. The answer
depends on the implementation, in other words.

If you are using VMS, ask on comp.os.vms. (Actually, you will
probably get more responses if you make a claim about how it works.
Human nature being what it is, a "wrong answer" brings out more
replies than a right one. This is why you should not trust any
answer you get in comp.lang.c, since if you are asking about, say,
the Presburg C compiler, the fact that the Presburg experts are
elsewhere means that wrong replies are not going to get corrected
here.)
 
K

kooladi

So, I gather this is an implementation issue.
Is there any "standard" way to link or even an "acceptable/
recommended" way to link defined?
 
W

Walter Roberson

kooladi said:
So, I gather this is an implementation issue.
Is there any "standard" way to link or even an "acceptable/
recommended" way to link defined?

The C standard does not deal with link order at all.

[OT]
The Unix 03 specification includes a utility named "c99", which
has mandatory options:

http://www.opengroup.org/onlinepubs/000095399/utilities/c99.html

-L directory
Change the algorithm of searching for the libraries named in
the -l objects to look in the directory named by the
directory pathname before looking in the usual places.
Directories named in -L options shall be searched in the
order specified. Implementations shall support at least ten
instances of this option in a single c99 command
invocation.

-l library
(The letter ell.) Search the library named:

liblibrary.a

A library shall be searched when its name is encountered, so
the placement of a -l operand is significant.


The above is consistant with the behaviour you encountered, but it
does not preclude other behaviours, since it does not define
what it means for a library to be "searched": "searched" could mean
that the entire symbol table list for the library would be read in
and remembered against future need.
 
F

Flash Gordon

CBFalconer wrote, On 22/04/08 01:44:
Yes. The first module that satisfies a function load request will
normally resolve that function forever. This sequence is normally
needed to make libraries flexible, but is not part of the standard.

Also it is not done by all implementations, so "yes" is not the correct
answer. You should have said "maybe" or "sometimes" or similar.
 
L

lawrence.jones

Richard Heathfield said:
What are you talking about, Chris? In comp.lang.c, even /right/ replies get
corrected!

No they don't!

-Larry Jones

Hey Doc, for 10 bucks I'll make sure you see those kids in the
waiting room again real soon! -- Calvin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,968
Messages
2,570,154
Members
46,702
Latest member
LukasConde

Latest Threads

Top