I'm new to this and don't understand why I should use dynamic linking when there is static linking.
- I know that
dynamic linkingreduces the size of the program file, but if it is acustom dynamic library, it will still have to be included in the installer. So, the final size of the app folder will not change. - If the external library is already installed on the machine, how to determine and specify its location in the project settings (vs, cmake, qmake). During
dynamic loadingyou can find out the location through system calls or Windows Registry. But how to do it duringdynamic linking?
Please help me, because of these two points I don't understand why dynamic linking is needed at all (I can understand the need for dynamic loading).
Dynamic linking not only reduces the file size of your final executable, but it also improves the memory footprint of your application. If you have two applications, both that are statically linked and both use a common, shared library, then two copies of that same shared library will reside in memory, which is a waste. In general you will always want dynamic linking to produce the smallest and most efficient code.
So when is it appropriate to use static linking? Well if you're unsure of the target machine's OS version, statically linking your application can ensure that your application runs regardless of their version. Also, secure applications, such as financial applications, are a good candidate because it isolates one process from another by providing each an independent environment and no code is shared between any applications. Further on, static linking offers faster execution because we copy the entire library content at compile time. Hence, we don’t have to run the query for unresolved symbols at runtime. Thus, we can execute a statically linked program faster than a dynamically linked one.