On load the dynamic library will have to assemble a table where the symbols are available that the code will access. The difference is very small and will not make any important difference. There may be gain in the library load that may already be in memory. As it can save memory consumption, there may be gain by having more chance of being cached.
There may be a overhead in function calls, as this test demonstrates.
In applications that use databases, where minimal access is absurdly more expensive than the executable load, it will not affect anything significantly.
It is possible in some situations to get better performance because of better optimization to compile statically. And there may be some gain for the reference location. Don’t expect miracles, or make a difference in most applications.
I particularly prefer static compilation whenever possible.
It is possible to place compiled libraries in folders where the system is instructed to search by default or that the application knows in some way that it should search in these locations. This is usually a headache and today one avoids a lot. We are no longer in time that this is an advantage.
It is better to leave the dynamic libraries when it is something that the operating system already has without ambiguity or if it will create a system of plugin/hot patch.
This can be useful.
More details on the subject at What is the difference between static and dynamic linkage?
I really liked your comment and the references, but there’s one thing that doesn’t go out of my mind, an application using dynamic libraries when it runs it will load everything into memory? Does static do that too? Because how am I developing a full C++ site wouldn’t it load all pages into memory? Thanks again.
– Pedro Soares
Well this is already another question, but in general the operating system only carries in memory what is necessary, ie load the table if symbols and what is being used.
– Maniero
Thank you so much for your help.
– Pedro Soares