8
Static libraries are just archives of object (
.o
) files, so you can't have embedded dependency information. Something like ar cr lib1.a foo.o bar.o [more object files]
will build your libraries.
Because there is no dependency information, your main program has to link both the libraries and it's important to link
lib1
after lib2
when lib2
depends on lib1
(otherwise the linker won't find the symbols that are unresolved in lib2
). A linking step could therefore look like this (assuming you use gcc
and your libraries are in the current directory):gcc -otest main.o -L. -Wl,-Bstatic -l2 -l1
-l1 -l2 -l1
will handle references in either direction including mutual recursion. – rici Aug 5 '17 at 14:49l2.lib
contain thel1.lib
objects as well? So when linking to the parent project ofl2.lib
onlyl2.lib
will be linked? – Royi Apr 20 at 6:54