Re: C run-time library

Tech-Archive recommends: Fix windows errors by optimizing your registry

From: Doug Harrison [MVP] (dsh_at_mvps.org)
Date: 06/02/04


Date: Wed, 02 Jun 2004 12:21:42 -0500

Gil Hamilton wrote:

>>From a brief look at VC6 CRT source, I can only see a couple of
>problem areas

<snip>

Kudos for going to the trouble to analyze this as suggested. However, note
that the VC6 CRT source you have is just a snapshot in time, and what I said
earlier concerning -Zl usage holds, namely, "Just be certain to vet
everything with a high powered microscope with each compiler version and CRT
flavor you use, because as a -Zl fan, you're sacrificing a useful link-time
antibugging feature, while making promises that can be broken for you at any
time."

>All in all, I'm (provisionally) a convert. I'll at least try the /Zl
>approach next time I need to create a library like this.

You'll still need to create release/debug versions of your libraries, and
your library clients will need to ensure they link to the correct one. In
addition, if you compile your library with /MT, your /MD users will call the
many __declspec(dllexport) functions in the CRT slightly less efficiently.
Finally, as already mentioned, MS doesn't find this approach suitable for
MFC or the C++ Standard Library. I think to consider this idea for libraries
that use the CRT is to borrow trouble, and I've got better things to do,
especially when the benefits conferred by /Zl are insignificant.

I'll leave you with these KB articles.

INFO: /Mx Compiler Options and the LIBC, LIBCMT, MSVCRT Libs
http://support.microsoft.com/?kbid=128641
<q>
All modules and static libraries within an application should use the same
compile options (/ML, /MT, or /MD) and link to the library cooresponding to
the selected option.
</q>

PRB: MFC and CRT Must Match in debug/release and static/dynamic
http://support.microsoft.com/?kbid=166504
<q>
If you are linking to any static libraries that also link to MFC or the CRT,
you should ensure that every static library shares the same properties
(debug/release, CRT-static/dynamic) as the application.
</q>

-- 
Doug Harrison
Microsoft MVP - Visual C++


Relevant Pages

  • Re: Problem with side-by-side information
    ... We will try to recompile everything, ... We never had a problem with redistributing CRT librarys with the ... versions of the CRT libraries. ... Without recompiling every library with SP1. ...
    (microsoft.public.vc.ide_general)
  • Re: How to dllimport a dllexported class
    ... You do need to link to the CRT, and all files in this library should ... Using DLLs is no different that using static libraries in that ... you need to treat it like static linking WRT having identical ... flawlessly for probably thousands of programs that use the CRT DLLs, ...
    (microsoft.public.dotnet.languages.vc)
  • Re: C run-time library
    ... >debug versions of my libraries. ... >> that use the CRT is to borrow trouble, and I've got better things to do, ... Most MS libraries are packaged purely as DLLs, ... CRT-specific static libraries as described by myself and Carl, ...
    (microsoft.public.vc.language)
  • Re: link with C runtime library
    ... be one of /Mxxx switches. ... Compiler and CRT are tightly coupled. ... We can not separate C and C++ libraries and they ...
    (microsoft.public.vc.language)
  • Re: Linking options for debugging
    ... Static libraries: You should link the application with a version of CRT ... you have to link the application with debug version of CRT to satisfy the ... DLLs: no (DLLs can be linked with other versions of CRT, ...
    (microsoft.public.vc.debugger)