dynamic-linking

What happens to global and static variables in a shared library when it is dynamically linked?

流过昼夜 提交于 2019-11-26 00:50:06
问题 I\'m trying to understand what happens when modules with globals and static variables are dynamically linked to an application. By modules, I mean each project in a solution (I work a lot with visual studio!). These modules are either built into *.lib or *.dll or the *.exe itself. I understand that the binary of an application contains global and static data of all the individual translation units (object files) in the data segment (and read only data segment if const). What happens when this

Static linking vs dynamic linking

南笙酒味 提交于 2019-11-25 23:17:19
问题 Are there any compelling performance reasons to choose static linking over dynamic linking or vice versa in certain situations? I\'ve heard or read the following, but I don\'t know enough on the subject to vouch for its veracity. 1) The difference in runtime performance between static linking and dynamic linking is usually negligible. 2) (1) is not true if using a profiling compiler that uses profile data to optimize program hotpaths because with static linking, the compiler can optimize both

When to use dynamic vs. static libraries

人走茶凉 提交于 2019-11-25 23:04:09
When creating a class library in C++, you can choose between dynamic ( .dll , .so ) and static ( .lib , .a ) libraries. What is the difference between them and when is it appropriate to use which? Static libraries increase the size of the code in your binary. They're always loaded and whatever version of the code you compiled with is the version of the code that will run. Dynamic libraries are stored and versioned separately. It's possible for a version of the dynamic library to be loaded that wasn't the original one that shipped with your code if the update is considered binary compatible