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