Using Visual Studio 2008 and its C/C++ compiler, how do I create a Win32 DLL that is dependent only on other Windows DLLs, and has no dependency on the Microsoft C runtime?<
for "Debug" mode try this:
for "Release" mode, do same steps except that selecting Multi-threaded (/MT) in the last step.
This causes any C Runtime function that used in your program to be statically-linked to your binary file.
Some Windows libraries depend on the C runtime (ODBC32.DLL, for example) so I think you are on a hiding to nothing here. Why would you want to do this, anyway?
Compile it with static microsoft lib.
You may have more dependencies on the CRT than you think. It tears down resources like thread local storage, and global class initializers are run by the CRT before main().
Consider linking with a static CRT, as someone said, and if you really really don't want to, use /NODEFAULTLIB and /ENTRY as someone else said.
Oh, and instead of reworking memcpy, consider using the super-fast compiler intrinsic for it. You can turn on intrinsics with /Oi.
The /NODEFAULTLIB
linker flag is not actually the proper flag. It will ignore all default libs, including others like uuid.lib
.
What you want is the /Zl
compiler option, "omit default library name in .OBJ".
Use the /NODEFAULTLIB linker option and (of course) make sure you have no actual dependencies on the runtime. You'll also have to specify & define your own entry point for the DLL using the /ENTRY linker option or alternatively have your own entry point function that matches the name expected by the compiler/linker (for a dll, that's _DllMainCRTStartup).
Matt Pietrek's article from way back when on LIBCTINY will probably have all the information you need: