Murrgon
2009-10-13 17:05:30 UTC
Ref URL: http://msdn.microsoft.com/en-us/library/2kzt1wy3%28VS.71%29.aspx
<quote>
Do not mix static and dynamic versions of the run-time libraries. Having more
than one copy of the run-time libraries in a process can cause problems,
because static data in one copy is not shared with the other copy. The linker
prevents you from linking with both static and dynamic versions within one
.exe file, but you can still end up with two (or more) copies of the run-time
libraries. For example, a dynamic-link library linked with the static
(non-DLL) versions of the run-time libraries can cause problems when used with
an .exe file that was linked with the dynamic (DLL) version of the run-time
libraries. (You should also avoid mixing the debug and non-debug versions of
the libraries in one process.)
</quote>
The above has long been established. However, I have discovered it to be a
*very* common occurrence in open source software to have different components
specify different code generation rules, which violates the above cautionary
statement. As a result I have a few questions that have been nagging me.
1) If I have a DLL that uses the shared/dll version of the CRT, but links with
a library that uses the static version of the crt, what do you end up with?
(Besides linker warnings). Does the code the library depend on actually get
linked in to the DLL?
2) Same situation as above, but you've told your DLL to ignore libcmt(d).lib.
Will this force the linker to ONLY use the shared/dll version of the CRT,
despite the other lib saying otherwise?
3) What are the dangers of having one DLL using the shared/dll version of the
CRT and another that has been statically linked with the CRT? This can happen
often when using 3rd party DLLs that don't provide the source to build it.
Thank you
Murrgon
<quote>
Do not mix static and dynamic versions of the run-time libraries. Having more
than one copy of the run-time libraries in a process can cause problems,
because static data in one copy is not shared with the other copy. The linker
prevents you from linking with both static and dynamic versions within one
.exe file, but you can still end up with two (or more) copies of the run-time
libraries. For example, a dynamic-link library linked with the static
(non-DLL) versions of the run-time libraries can cause problems when used with
an .exe file that was linked with the dynamic (DLL) version of the run-time
libraries. (You should also avoid mixing the debug and non-debug versions of
the libraries in one process.)
</quote>
The above has long been established. However, I have discovered it to be a
*very* common occurrence in open source software to have different components
specify different code generation rules, which violates the above cautionary
statement. As a result I have a few questions that have been nagging me.
1) If I have a DLL that uses the shared/dll version of the CRT, but links with
a library that uses the static version of the crt, what do you end up with?
(Besides linker warnings). Does the code the library depend on actually get
linked in to the DLL?
2) Same situation as above, but you've told your DLL to ignore libcmt(d).lib.
Will this force the linker to ONLY use the shared/dll version of the CRT,
despite the other lib saying otherwise?
3) What are the dangers of having one DLL using the shared/dll version of the
CRT and another that has been statically linked with the CRT? This can happen
often when using 3rd party DLLs that don't provide the source to build it.
Thank you
Murrgon