Static or dynamic linking the CRT, MFC, ATL, etc

前端 未结 7 733
一整个雨季
一整个雨季 2020-12-10 11:19

Back in the 90s when I first started out with MFC I used to dynamically link my apps and shipped the relevant MFC DLLs. This caused me a few issues (DLL hell!) and I switch

7条回答
  •  有刺的猬
    2020-12-10 11:42

    As long as you keep your usage limited to certain libraries and do not use any dll's then you should be good.

    Unfortunately, there are some libraries that you cannot link statically. The best example I have is OpenMP. If you take advantage of Visual Studio's OpenMP support, you will have to make sure the runtime is installed (in this case vcomp.dll).

    If you do use dll's then you can't pass some items back and forth without some serious gymnastics. std::strings come to mind. If your exe and dll are dynamically linked then the allocation takes place in in the CRT. Otherwise your program may try to allocate the string on one side and deallocate it on the other. Bad things ensue...

    That said, I still statically link my exe's and dll's. It does reduce a lot of the variablilty in the install and I consider that well worth the few limitations.

提交回复
热议问题