title: MSVC C++ find out what function requires linker symbol
body: <p>I have a special situation. In my project the kernel32.lib is replaced by a substition library (Windows realtime extension RTX). So I do not link to kernel32.lib, user32.lib, etc.</p>
  <p>This substitution library (rtapi.lib) is supposed to have the same external ABI as the kernel32 library. This all worked fine when compiling under Visual Studio 2019. But now I would like to upgrade to Visual Studio 2022 and all of a sudden I get a number of linker errors:</p>
  <pre><code>1&gt;libcpmtd.lib(winapisupp.obj) : error LNK2019: unresolved external symbol __imp_SetFileInformationByHandle referenced in function __crtSetFileInformationByHandle
  1&gt;libcpmtd.lib(winapisupp.obj) : error LNK2019: unresolved external symbol __imp_InitializeSRWLock referenced in function __crtInitializeSRWLock
  1&gt;libcpmtd.lib(winapisupp.obj) : error LNK2019: unresolved external symbol __imp_ReleaseSRWLockExclusive referenced in function __crtReleaseSRWLockExclusive
  1&gt;libcpmtd.lib(winapisupp.obj) : error LNK2019: unresolved external symbol __imp_AcquireSRWLockExclusive referenced in function __crtAcquireSRWLockExclusive
  1&gt;libcpmtd.lib(winapisupp.obj) : error LNK2019: unresolved external symbol __imp_InitializeConditionVariable referenced in function __crtInitializeConditionVariable
  1&gt;libcpmtd.lib(winapisupp.obj) : error LNK2019: unresolved external symbol __imp_WakeConditionVariable referenced in function __crtWakeConditionVariable
  1&gt;libcpmtd.lib(winapisupp.obj) : error LNK2019: unresolved external symbol __imp_WakeAllConditionVariable referenced in function __crtWakeAllConditionVariable
  1&gt;libcpmtd.lib(winapisupp.obj) : error LNK2019: unresolved external symbol __imp_SleepConditionVariableCS referenced in function __crtSleepConditionVariableCS
  1&gt;libcpmtd.lib(winapisupp.obj) : error LNK2019: unresolved external symbol __imp_SleepConditionVariableSRW referenced in function __crtSleepConditionVariableSRW
  1&gt;libcpmtd.lib(winapisupp.obj) : error LNK2019: unresolved external symbol __imp_CreateEventExW referenced in function __crtCreateEventExW
  1&gt;libcpmtd.lib(winapisupp.obj) : error LNK2019: unresolved external symbol __imp_CreateSemaphoreExW referenced in function __crtCreateSemaphoreExW
  1&gt;libcpmtd.lib(winapisupp.obj) : error LNK2019: unresolved external symbol __imp_FlushProcessWriteBuffers referenced in function __crtFlushProcessWriteBuffers
  1&gt;libcpmtd.lib(winapisupp.obj) : error LNK2019: unresolved external symbol __imp_FreeLibraryWhenCallbackReturns referenced in function __crtFreeLibraryWhenCallbackReturns
  1&gt;libcpmtd.lib(winapisupp.obj) : error LNK2019: unresolved external symbol __imp_CreateThreadpoolWork referenced in function __crtCreateThreadpoolWork
  1&gt;libcpmtd.lib(winapisupp.obj) : error LNK2019: unresolved external symbol __imp_SubmitThreadpoolWork referenced in function __crtSubmitThreadpoolWork
  1&gt;libcpmtd.lib(winapisupp.obj) : error LNK2019: unresolved external symbol __imp_CloseThreadpoolWork referenced in function __crtCloseThreadpoolWork
  1&gt;libcpmtd.lib(winapisupp.obj) : error LNK2019: unresolved external symbol __imp_CreateThreadpoolTimer referenced in function __crtCreateThreadpoolTimer
  1&gt;libcpmtd.lib(winapisupp.obj) : error LNK2019: unresolved external symbol __imp_SetThreadpoolTimer referenced in function __crtSetThreadpoolTimer
  1&gt;libcpmtd.lib(winapisupp.obj) : error LNK2019: unresolved external symbol __imp_WaitForThreadpoolTimerCallbacks referenced in function __crtWaitForThreadpoolTimerCallbacks
  1&gt;libcpmtd.lib(winapisupp.obj) : error LNK2019: unresolved external symbol __imp_CloseThreadpoolTimer referenced in function __crtCloseThreadpoolTimer
  1&gt;libcpmtd.lib(winapisupp.obj) : error LNK2019: unresolved external symbol __imp_CreateThreadpoolWait referenced in function __crtCreateThreadpoolWait
  1&gt;libcpmtd.lib(winapisupp.obj) : error LNK2019: unresolved external symbol __imp_SetThreadpoolWait referenced in function __crtSetThreadpoolWait
  1&gt;libcpmtd.lib(winapisupp.obj) : error LNK2019: unresolved external symbol __imp_CloseThreadpoolWait referenced in function __crtCloseThreadpoolWait
  1&gt;libcpmtd.lib(winapisupp.obj) : error LNK2019: unresolved external symbol __imp_GetFileInformationByHandleEx referenced in function __crtGetFileInformationByHandleEx
  1&gt;libcpmtd.lib(winapisupp.obj) : error LNK2019: unresolved external symbol __imp_CreateSymbolicLinkW referenced in function __crtCreateSymbolicLinkW
  </code></pre>
  <p>My guess is that in winapisupp.cpp which is part of the STL requires now some newer functions in kernel32. My guess is that the newer version of the STL uses some function to support the new parallel alrogithms. Therefore it requires os services like a task scheduler or a thread pool. In the <a href="https://github.com/microsoft/STL/blob/main/stl/src/winapisupp.cpp#L320" rel="nofollow noreferrer">source code on github</a> I see this:</p>
  <pre><code>// TRANSITION, ABI: preserved for binary compatibility
  extern &quot;C&quot; VOID __cdecl __crtSubmitThreadpoolWork(_Inout_ PTP_WORK const pwk) {
      SubmitThreadpoolWork(pwk);
  }
  </code></pre>
  <p>and</p>
  <pre><code>STOREFUNCTIONPOINTER(hKernel32, SubmitThreadpoolWork);
  </code></pre>
  <p>The next step that I tried was to diff the output of dumpbin for the two versions of libcpmtd.lib</p>
  <pre><code>PS C:\&gt; dumpbin /all &quot;C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.29.30133\lib\x64\libcpmtd.lib&quot; &gt; c:\dev\libcpmtd.lib.2022.sym
  PS C:\&gt; dumpbin /all &quot;C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.27.29110\lib\x64\libcpmtd.lib&quot; &gt; c:\dev\libcpmtd.lib.2019.sym
  </code></pre>
  <p>In the diff between these two versions I see that in the 2022 version 70 symbols have been added. Among them, these I got from the linker errors.</p>
  <p>So my program calls a function that calls through many sub calls, for example the __crtSubmitThreadpoolWork function. My question now is how I can find out what call graph requires this function?</p>
  <p>It would help if the STL had a #define to avoid using these new kernel32 functions (like e.g. DISABLE_PARALLEL_ALGORITHMS). But since I doubt that this is available, I need to replace the parts of the STL that requires these by another library (maybe absl?)</p>