|
1 | 1 | --- |
2 | 2 | title: "C runtime (CRT) and C++ standard library (STL) lib files" |
3 | 3 | description: "List of Microsoft C runtime and C++ standard library (STL) lib files that you can link against and their associated compiler options and preprocessor directives." |
4 | | -ms.date: "3/5/2021" |
| 4 | +ms.date: 02/23/2026 |
5 | 5 | ms.topic: "reference" |
6 | 6 | helpviewer_keywords: ["MSVCR71.dll", "libraries [C++], multithreaded", "library files, run-time", "LIBCMT.lib", "LIBCP.lib", "LIBCPMT.lib", "run-time libraries, C", "CRT, release versions", "MSVCP71.dll", "LIBC.lib", "libraries [C++]", "libraries [C++], run-time", "linking [C++], libraries", "STL libraries", "Microsoft standard template libraries"] |
7 | 7 | --- |
@@ -104,49 +104,6 @@ It's also possible to avoid some of these issues if all of the images in your pr |
104 | 104 |
|
105 | 105 | Be careful if your program passes certain CRT resources across DLL boundaries. Resources such as file handles, locales, and environment variables can cause problems, even when using the same version of the CRT. For more information on the issues involved and how to resolve them, see [Potential errors passing CRT objects across DLL boundaries](./potential-errors-passing-crt-objects-across-dll-boundaries.md). |
106 | 106 |
|
107 | | -### Problems with statically linked CRT libraries |
108 | | - |
109 | | -There are three forms of the C Run-time library provided with the Win32 SDK: |
110 | | - |
111 | | -- `LIBC.LIB` is a statically linked library for single-threaded programs. |
112 | | -- `LIBCMT.LIB` is a statically linked library that supports multithreaded programs. |
113 | | -- `CRTDLL.LIB` is an import library for `CRTDLL.DLL` that also supports multithreaded programs. `CRTDLL.DLL` is part of Windows NT. |
114 | | - |
115 | | -Microsoft Visual C++ 32-bit edition contains these three forms as well, however, the CRT in a DLL is named `MSVCRT.LIB`. The DLL is redistributable. Its name depends on the version of VC++ (that is, `MSVCRT10.DLL` or `MSVCRT20.DLL`). Note however, that `MSVCRT10.DLL` is not supported on Win32s, while `CRTDLL.LIB` is supported on Win32s. `MSVCRT20.DLL` comes in two versions: one for Windows NT and the other for Win32s. |
116 | | - |
117 | | -If an application that makes C runtime calls links to a DLL that also makes C runtime calls, be aware that if they are both linked with one of the statically linked C runtime libraries, the `.EXE` and DLL will have separate copies of all C runtime functions and global variables. This means that C runtime data cannot be shared between the `.EXE` and the DLL. Some of the problems that can occur are: |
118 | | - |
119 | | -- Passing buffered stream handles from the .EXE/DLL to the other module |
120 | | -- Allocating memory with a C runtime call in the .EXE/DLL and reallocating or freeing it in the other module |
121 | | -- Checking or setting the value of the global `errno` variable in the .EXE/DLL and expecting it to be the same in the other module. A related problem is calling `perror()` in the opposite module from where the C runtime error occurred, since `perror()` uses `errno`. |
122 | | - |
123 | | -To avoid these problems, link both the `.EXE` and DLL with `CRTDLL.LIB` or `MSVCRT.LIB`, which allows both the `.EXE` and DLL to use the common set of functions and data contained within CRT in a DLL, and C runtime data such as stream handles can then be shared by both the `.EXE` and DLL. |
124 | | - |
125 | | -### Mixing library types |
126 | | - |
127 | | -You can link your DLL with `CRTDLL.LIB`/`MSVCRT.LIB` regardless of what your `.EXE` is linked with if you avoid mixing CRT data structures and passing CRT file handles or CRT `FILE*` pointers to other modules. |
128 | | - |
129 | | -When mixing library types adhere to the following: |
130 | | - |
131 | | -- CRT file handles may only be operated on by the CRT module that created them. |
132 | | -- CRT `FILE*` pointers may only be operated on by the CRT module that created them. |
133 | | -- Memory allocated with the CRT function `malloc()` may only be freed or reallocated by the CRT module that allocated it. |
134 | | - |
135 | | -To illustrate this, consider the following example: |
136 | | - |
137 | | -- `.EXE` is linked with `MSVCRT.LIB` |
138 | | -- DLL A is linked with `LIBCMT.LIB` |
139 | | -- DLL B is linked with `CRTDLL.LIB` |
140 | | - |
141 | | -If the `.EXE` creates a CRT file handle using `_create()` or `_open()`, this file handle may only be passed to `_lseek()`, `_read()`, `_write()`, `_close()`, etc. in the `.EXE` file. Do not pass this CRT file handle to either DLL. Do not pass a CRT file handle obtained from either DLL to the other DLL or to the `.EXE`. |
142 | | - |
143 | | -If DLL A allocates a block of memory with `malloc()`, only DLL A may call `free()`, `_expand()`, or `realloc()` to operate on that block. You cannot call `malloc()` from DLL A and try to free that block from the `.EXE` or from DLL B. |
144 | | - |
145 | | -> [!NOTE] |
146 | | -> If all three modules were linked with `CRTDLL.LIB` or all three were linked with `MSVCRT.LIB`, these restrictions would not apply. |
147 | | -
|
148 | | -When linking DLLs with `LIBC.LIB`, be aware that if there is a possibility that such a DLL will be called by a multithreaded program, the DLL will not support multiple threads running in the DLL at the same time, which can cause major problems. If there is a possibility that the DLL will be called by multithreaded programs, be sure to link it with one of the libraries that support multithreaded programs (`LIBCMT.LIB`, `CRTDLL.LIB`, or `MSVCRT.LIB`). |
149 | | - |
150 | 107 | ## See also |
151 | 108 |
|
152 | 109 | [C runtime library reference](./c-run-time-library-reference.md)\ |
|
0 commit comments