Regular DLL using: MFC Shared vs MFC is statically linked

When we create a DLL using Visual studio (VC8 or 9), we get the create Regular DLL option

using MFC as shared DLL 

or

  using MFC as static library 

How do they differ? Which one is appropriate to use?

+4
source share
3 answers

[I think I got my answer now]

If you use the MFC DLL as a dynamic link, your code will need the Microsoft Foundation Library (in particular, the version required by your code) along with your application or dll at the end of the user. Thus, your installation package will contain

  • Your application / DLL and supporting files
  • All MFC Dll

This increases the size of the installation package and also allows the user to download the installation.

If you reference MFC as a static library, your code will work even without the MFC DLLs available at the end of the user. The reason is pretty simple because all the MFC libraries that you listed in your code will be associated with your application or dll. This means that the MFC libraries used in your / dll application become part of your binary code; however your application / dll will be a bit larger.

+4
source

A static library means that the code you use from the library is included in your executable file. Because of this, you do not need to send the library or require the end user to have it on their machine. However, this inflates the size of your executable file and links you to this version of the library, so if you need to update only the library, you must send a new executable file.

A shared library calls the library at the time it needs it (runtime) to execute the code, but this requires the user to have (usually a specific or minimal version) installed on his machine. You can also distribute the desired version of the library with your application if you need to.

Which is better, I do not know. I am not a Windows C ++ or MFC programmer, so I could not say. On my Linux servers, the applications I write are usually server-side and therefore use shared libraries.

It depends on how your application should be used, distributed, updated, how often the MFC library changes, if it is available at all on the user's PC, etc.

+11
source

Another consideration is the maintenance of your application.

If you send MSFT redis, dynamically link to its libraries, and then MSFT later β€œfixes” some significant flaws in the DLL, they fix the DLL on your client machines through Window Update. If you are statically communicating, you will need to immediately update all your clients.

Of course, if you are concerned that a patched DLL might crash your application (because you rely on unspecified behavior), you can handle maintenance (and testing) directly with your client.

+2
source

Source: https://habr.com/ru/post/1307138/


All Articles