LIB vs DLL#
.lib / .a
and .dll / .so
files are seen everywhere, from the OS to custom programs.What are those ?#
code reuse - with
DLL / SO
files, you can easily build once - use multiple times the same code along various projects.sharing obfuscated code - since the code is already compiled, it is nearly impossible to retro-engineer it. Thus, you can allow someone to reuse it without impacting your intellectual property on the file.
plugin system - for non-interpreted languages (such as C++), it allows your code to be extended with the final user’s handmade code.
smaller rebuild and easier update - since the code can be directly used, cutting your project into multiple subfiles allows you to rebuild only the required parts of your project, decreasing the build time. Also, if you’d like to update some parts of your project, you can modify and transmit only the concerned parts.
All or a small portion of the code it contains can be given out thanks to header
files. Without them, it will be nearly impossible to use.
.lib / .a - the static libraries#
.lib
(Windows) or .a
(Unix) files are known as static libraries.A.exe
and B.exe
are built against a .lib
file, both will contain all the used code from within the library.dll / so
ones. Please read the next chapter..dll / .so - the dynamic libraries#
.dll
(Windows) or .so
(Unix) files are known as dynamically linked / shared libraries.PATH
variable or inside a specific folder.Warning
The data is NOT shared between the programs. If a .dll
contains a string, it will be created on the program stack or heap memory.
Implicit and explicit linking#
.lib, .a or .def
). Those libs do not contain code, but rather some description (adresses, entry point …) on how to call and use the library..lib / .so
files to the linker.Summary#
LIB / A |
DLL / SO |
---|---|
Embedded code (during compilation) |
Linked at run-time (program execution) |
Not recompiled, but copied in each program |
Can be used by multiple programs (no data sharing) |
No versioning issues (as code is not shared between apps) |
A program installing a newer or older version of the same library may make other programs crash |
Faster run since the code is embedded |
Slower execution while the libraries are loaded |
Bigger memory use, as the whole code is embeeded |
Cut into multiple files that can be loaded and unloaded on the fly |
Can sometimes be a helper to load DLL files, containing entry points |