I am trying to understand how the linking process works for C programs in VS2019. According to Microsoft Docs, I need to pass the \MD option to link against ucrt.lib.
I wrote an empty main function and compiled+linked it to Sample.exe under two different configurations. In the default Debug configuration, the final binary produces the following output on running dumpbin /imports Sample.exe:
VCRUNTIME140D.dll
41B098 Import Address Table
41B2A4 Import Name Table
0 time date stamp
0 Index of first forwarder reference
2E __vcrt_GetModuleFileNameW
35 _except_handler4_common
48 memset
1D __current_exception_context
1C __current_exception
2F __vcrt_GetModuleHandleW
31 __vcrt_LoadLibraryExW
25 __std_type_info_destroy_list
ucrtbased.dll
41B0E8 Import Address Table
41B2F4 Import Name Table
0 time date stamp
0 Index of first forwarder reference
2EE _seh_filter_dll
545 strcat_s
2E2 _register_onexit_function
10C _execute_onexit_table
E8 _crt_atexit
E7 _crt_at_quick_exit
E0 _controlfp_s
566 terminate
3C9 _wmakepath_s
3E5 _wsplitpath_s
57F wcscpy_s
8E __stdio_common_vsprintf_s
549 strcpy_s
73 __p__commode
2FA _set_new_mode
DB _configthreadlocale
2E3 _register_thread_local_exe_atexit_callback
C5 _c_exit
CA _cexit
70 __p___argv
6F __p___argc
2F7 _set_fmode
111 _exit
476 exit
19A _initterm_e
199 _initterm
162 _get_initial_narrow_environment
196 _initialize_narrow_environment
DC _configure_narrow_argv
81 __setusermatherr
2F2 _set_app_type
2EF _seh_filter_exe
15 _CrtDbgReportW
14 _CrtDbgReport
197 _initialize_onexit_table
KERNEL32.dll
41B000 Import Address Table
41B20C Import Name Table
0 time date stamp
0 Index of first forwarder reference
345 HeapAlloc
37F IsDebuggerPresent
462 RaiseException
3EF MultiByteToWideChar
5FE WideCharToMultiByte
44D QueryPerformanceCounter
218 GetCurrentProcessId
2E9 GetSystemTimeAsFileTime
58C TerminateProcess
217 GetCurrentProcess
2AE GetProcAddress
1AB FreeLibrary
5CE VirtualQuery
2B4 GetProcessHeap
349 HeapFree
21C GetCurrentThreadId
261 GetLastError
278 GetModuleHandleW
386 IsProcessorFeaturePresent
2D0 GetStartupInfoW
56D SetUnhandledExceptionFilter
5AD UnhandledExceptionFilter
363 InitializeSListHead
Whereas, under the Release configuration, I am getting this:
VCRUNTIME140.dll
402034 Import Address Table
402608 Import Name Table
0 time date stamp
0 Index of first forwarder reference
48 memset
1D __current_exception_context
1C __current_exception
35 _except_handler4_common
KERNEL32.dll
402000 Import Address Table
4025D4 Import Name Table
0 time date stamp
0 Index of first forwarder reference
386 IsProcessorFeaturePresent
37F IsDebuggerPresent
363 InitializeSListHead
2E9 GetSystemTimeAsFileTime
21C GetCurrentThreadId
5AD UnhandledExceptionFilter
56D SetUnhandledExceptionFilter
217 GetCurrentProcess
58C TerminateProcess
218 GetCurrentProcessId
44D QueryPerformanceCounter
278 GetModuleHandleW
api-ms-win-crt-runtime-l1-1-0.dll
402060 Import Address Table
402634 Import Name Table
0 time date stamp
0 Index of first forwarder reference
44 _set_app_type
39 _initterm_e
58 exit
25 _exit
35 _initialize_narrow_environment
5 __p___argc
6 __p___argv
17 _cexit
16 _c_exit
3F _register_thread_local_exe_atexit_callback
19 _configure_narrow_argv
42 _seh_filter_exe
2A _get_initial_narrow_environment
36 _initialize_onexit_table
3E _register_onexit_function
1F _crt_atexit
1D _controlfp_s
6A terminate
38 _initterm
api-ms-win-crt-math-l1-1-0.dll
402058 Import Address Table
40262C Import Name Table
0 time date stamp
0 Index of first forwarder reference
2E __setusermatherr
api-ms-win-crt-stdio-l1-1-0.dll
4020B0 Import Address Table
402684 Import Name Table
0 time date stamp
0 Index of first forwarder reference
54 _set_fmode
1 __p__commode
api-ms-win-crt-locale-l1-1-0.dll
402050 Import Address Table
402624 Import Name Table
0 time date stamp
0 Index of first forwarder reference
8 _configthreadlocale
api-ms-win-crt-heap-l1-1-0.dll
402048 Import Address Table
40261C Import Name Table
0 time date stamp
0 Index of first forwarder reference
16 _set_new_mode
The link on top talks about how two different versions of the DLLs are used for Release and Debug configurations but here, I am linking to two different sets of DLLs. Why is this happening? The docs say that ucrt.dll is sufficient for the Standard C library functions. How do I just link to that?
Also, why do I require VCRUNTIME DLL when I am not using any C++?