Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

exe and dll sharing the same static libraries

i have my solution for my application set up the following way - ( i am using Visual Studio and this is a VC++ project )

App Library dependency diagram

NOTE: Blue projects are compiled as static libraries.

as you can see, the exe and dll shares some of the static libraries ( core.lib and utils.lib ) and exe in-turn uses the DLL ( through "load time dynamic linking" using import library).

my question is is it a correct dependency-setup to have ? the problem i see is, when this app is up and running, there will be some duplicate code in the process address space right ? meaning, all the functions that are there in Core.lib and Utils.lib will appear twice right ? cos, the Exe and DLL will have this code separately compiled into them.

if yes, one way of dealing with the above issue is to move the code exclusive to dll or keep in exe and share it (b/w exe and dll) through import/export. but i have many class objects in core and utils and i dont like the idea of exporting/importing these class objects ( by appending __declspec(dllimport/dllexport)) in the header files and besides i might end up adding this to lot of dependent class objects

this is my understanding and i might be wrong. please suggest corrections and what is the usual approach followed to deal with such problems ?

Regards,

like image 918
naiveCoder Avatar asked Aug 29 '13 14:08

naiveCoder


1 Answers

if you go DLL you must go DLL all the way, all dependencies down to the c-runtime. code duplication (memory footprint) is not the worst problem. remember, memory allocated by the app cannot be freed by a dll and vice versa, unless both use the very same runtime (dll).

like image 54
stefan Avatar answered Oct 14 '22 07:10

stefan