简体   繁体   中英

Link to the system C library msvcrt.dll

In Windows, there is a default C library msvcrt.dll.

Is it possible to write simple C programs that uses functions from msvcrt.dll only? That would relieve the need for installing the recent VC runtime.

I think a possible way is to explicitly specify /NODEFAULTLIB, and use the dll import procedure to import msvcrt.dll functions.

Anyone has a clue?

You can use MinGW-w64 GCC, which links to msvcrt.dll for exactly the reason you say.

You can find downloads here . You can link your programs with -static-libgcc -static-libstdc++ if you don't want to redistribute any DLLs.

That being said, you can just simply ship the msvcr*.dll files alongside your executable, no need to install anything.

You don't want to use msvcrt.dll.

  • It is very old and therefore doesn't meet modern C run-time library specifications.
  • It exists primarily for backward compatibility and for use by certain system components that have special requirements.
  • You cannot expect that it'll be widely patched if a security problem is discovered.
  • There is no guarantee that a binary made with a modern compiler is going to be compatible with the ABI in msvcrt.dll.
  • Modern C and C++ compilers have intimate knowledge and expectations of their run-time libraries with regard to optimizations, setup, and teardown, so you shouldn't mix and match them.

Use the run-time library that comes with your compiler. You can link to it statically if you don't want to worry about redistributing it, or you can read about the proper ways of redistributing it with your application.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM