For example, if I have a lib A
that has dependency on lib B
, then do I need to link both lib A
and lib B
or only lib A
, when I write a program C
that depends on lib A
?
Static libraries are not linked. Notice that the tool creating a static library is not a linker—it's ar
(archiver) on Unix-like platforms and lib
(librarian) when using the MS toolchain. This is an important point to remember when dealing with static libraries and linking.
And it should answer your question. Unless the author of A
took explicit extra steps to put the contents of B
into A
, you'll need to link against both A
and B
.
A library (A) that needs another library (B) will link that library to the exe. This is because A doesnt need to know the code in B, only the exe does. This is because in the linking stage, all code in the libraries are effectively copied into the exe, therefore all references to B from A will be resolved at that step.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With