Say I have libA. It depends on, for example, libSomething for the simple fact that a non-inline method of libA makes a call to a method in libSomething.h. How does the dependency link up in this case? Does libA have to statically link to libSomething when it is compiled, or will a user of libA (an application using libA) need to link to both libA and libSomething?
Thanks
Static libraries are either merged with other static libraries and object files during building/linking to form a single executable or loaded at run-time into the address space of their corresponding executable at a static memory offset determined at compile-time/link-time.
Static Linking and Static Libraries is the result of the linker making copy of all used library functions to the executable file. Static Linking creates larger binary files, and need more space on disk and main memory.
In computer science, a static library or statically-linked library is a set of routines, external functions and variables which are resolved in a caller at compile-time and copied into a target application by a compiler, linker, or binder, producing an object file and a stand-alone executable.
Static linking is the result of the linker copying all library routines used in the program into the executable image. This may require more disk space and memory than dynamic linking, but is both faster and more portable, since it does not require the presence of the library on the system where it is run.
Static linking is just copying the whole items (functions, constants, etc) into the resulting executable. If a static library's code contains references to some shared library items, these references will become dependencies in the resulting executable. The same holds if you link a library instead of executable.
This thread discusses how it happens in Linux.
A static library is more or less a simple archive of unlinked binary object files (*.o or *.obj), when compiling the archive, no checking is done for dependencies. When one linked one's binary executable (or shared library / DLL) the linker checks for all the necessary dependencies and only then will alert you to any issues.
During the build process the compiler translates code into a temporary format, let's call it an object file. In the object file, there is a list of symbols that the compiler could not resolve, usually definitions elsewhere. The linking phase is in charge of resolving these symbols.
The build process feeds files to the linker until all symbols are resolved. There is no physical dependency lists, just lists of symbols to resolve. This allows for symbols to be resolved by using different libraries. For example, one may want to use a Windows library for Windows specific issues; a linux library for linux specific issues. This does not explicitly state that a program is dependent on a Windows library; it could also be dependent on the Linux one.
Some compilers can generate dependency lists, usually for usage in a build process. However, the ultimate responsibility is up to the programmer.
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