c++buildlinkerdependencies

Redundant occurances of a statically linked library?


First, we have a system project, which provides some abstract architecture classes. Then, several module projects with different names inherit from one of system's classes to implement specialized features. Last, an application brings both together. It instantiates the base architecture from system and attaches modules to it.

This gives the following dependencies.

When I build this setup, do all module libraries contain copies of the system library? If so, can I prevent this behavior? In the end, they are, anyway, statically linked together in the executable along with the system library.


Solution

  • When you build a library, nothing gets linked. A library is just a bunch of object files stuck together in an archive. It's only when you build an application that the linker gets involved, pulling in the pieces that are needed by the various components of the application.