Holy placeholder name overload, batman. Let's first replace A, B, and C, with libstatic
, libshared
, and myapp
to make things a little more legible:
Suppose you have static library libstatic
, and
dynamic shared object library libshared
and
your program myapp
under linux. Suppose
that library libstatic
calls functions from
library libshared
and your program (myapp
) calls
functions from library libstatic
. Now suppose
that all functions that myapp
calls in libstatic
make no use of functions in libshared
.
To compile myapp
will it be enough to link
just libstatic
and omit libshared
and furthermore can
your program myapp
be run on a system
without library libshared
installed?
So the way I understand your question, there is a library libstatic
, some functions in which make use of libshared
. You want to know: if I don't use any of the libstatic
functions that are dependent on libshared
, will myapp
link and run without libshared
?
The answer is yes, so long as two things are true:
The calls you make into libstatic
do not depend on libshared
directly or indirectly. Meaning that if myapp
calls a function in libstatic
which calls another function in libstatic
which calls a function in libshared
, then myapp
is now dependent on libshared
.
The calls you make into libstatic
do not depend on any function in libstatic
whose implementation appears in the same compilation unit (object file) with a call to libshared
. The linker brings in code from the static library at the level of object files, not at the level of individual functions. And remember, this dependency is similarly chained, so if you call a function in foo.o
, and something else in foo.o
calls a function in bar.o
, and something in bar.o
depends on libshared
, you're toast.
When you link in a static library into an application, only the object files that contain the symbols used (directly or indirectly) are linked. So if it turns out that none of the object files that myapp
ends up needing from libstatic
depend on libshared
, then myapp
doesn't depend on libshared
.