2

I'm using VS2015 Community. I have obtained some C code that I'm trying to build. It is all in C and I have made a project as a Console Application.

When I build I get the below errors. The problem is that __stdio_common_vsprintf_s cannot be found during the link process. So I searched the internet for the symbols but don't get any useful information.

I am using the Runtime Library setting called Multi-threaded (/MT).

I have tried adding #define STDC_WANT_LIB_EXT1 1 before all includes but that did not help. I have searched for this problem and have not found any postings that help.

So I searched all of the VS libraries and got lots of hits but I don't know which are definitions and which are references. Then I searched all of the .h files in the VS include folder but no hits.

I suspect there may be another library that I need but don't know what it is. Does anyone have any ideas?

1>LIBCMT.lib(_error_.obj) : error LNK2019: unresolved external symbol ___stdio_common_vsprintf_s referenced in function __vsprintf_s_l
1>LIBCMT.lib(_pdblkup_.obj) : error LNK2019: unresolved external symbol ___vcrt_GetModuleFileNameW referenced in function "int __cdecl _RTC_GetSrcLine(unsigned char *,wchar_t *,unsigned long,int *,wchar_t *,unsigned long)" (?_RTC_GetSrcLine@@YAHPAEPA_WKPAH1K@Z)
1>LIBCMT.lib(_pdblkup_.obj) : error LNK2019: unresolved external symbol ___vcrt_LoadLibraryExW referenced in function "struct HINSTANCE__ * __cdecl GetPdbDllFromInstallPath(void)" (?GetPdbDllFromInstallPath@@YAPAUHINSTANCE__@@XZ)
1>MSVCRTD.lib(_chandler4gs_.obj) : error LNK2019: unresolved external symbol __except_handler4_common referenced in function __except_handler4
1>W:\efifs\Debug\testing.exe : fatal error LNK1120: 6 unresolved externals

Here are my options:

Compile
----------
/GS 
/analyze- 
/W3 
/Zc:wchar_t 
/I"W:\efifs\\gnu-efi\inc" 
/I"W:\efifs\\gnu-efi\inc\ia32" 
/I"W:\efifs\\grub\include" 
/I"W:\efifs\\grub-core\lib\minilzo" 
/I"W:\efifs\testing\" 
/I"W:\efifs\\gnu-efi\inc\protocol" 
/I"W:\efifs\\gnu-efi\lib" 
/I"W:\efifs\\include" 
/I"W:\efifs\\grub\grub-core\lib\minilzo" 
/I"W:\efifs\.msvc" 
/ZI 
/Gm 
/Od 
/Fd"Debug\vc140.pdb" 
/Zc:inline 
/fp:precise 
/D "__STDC_WANT_LIB_EXT1__=1" 
/D "_UNICODE" 
/D "UNICODE" 
/D "GRUB_FILE=__FILE__" 
/D "HAVE_USE_MS_ABI" 
/D "GNU_EFI_USE_EXTERNAL_STDARG" 
/D "DRIVERNAME=testing" 
/D "WIN32" 
/D "_DEBUG" 
/D "_CONSOLE" 
/errorReport:prompt 
/WX- 
/Zc:forScope 
/RTC1 
/Gd 
/Oy- 
/MT 
/Fa"Debug\" 
/EHsc 
/nologo 
/Fo"Debug\" 
/Fp"Debug\testing.pch" 

Link
-----
/OUT:"W:\efifs\Debug\testing.exe" 
/MANIFEST 
/NXCOMPAT 
/PDB:"W:\efifs\Debug\testing.pdb" 
/DYNAMICBASE "efifs.lib" "grub.lib" "gnu-efi.lib" "kernel32.lib" "user32.lib" "gdi32.lib" "winspool.lib" "comdlg32.lib" "advapi32.lib" "shell32.lib" "ole32.lib" "oleaut32.lib" "uuid.lib" "odbc32.lib" "odbccp32.lib" 
/MACHINE:X86 
/INCREMENTAL 
/PGD:"W:\efifs\Debug\testing.pgd" 
/SUBSYSTEM:CONSOLE 
/MANIFESTUAC:"level='asInvoker' uiAccess='false'" 
/ManifestFile:"Debug\testing.exe.intermediate.manifest" 
/ERRORREPORT:PROMPT 
/NOLOGO 
/LIBPATH:"W:\efifs\testing\\grub" 
/LIBPATH:"W:\efifs\testing\\efifs" 
/LIBPATH:"W:\efifs\testing\\gnu-efi" 
/TLBID:1 
eddyq
  • 879
  • 1
  • 13
  • 25
  • Did you add `#define __STDC_WANT_LIB_EXT1__ 1` before including the headers? – Lundin Sep 23 '15 at 13:08
  • @Olaf Since when are compiler messages not an unreadable mess? No fault of the poster. – Lundin Sep 23 '15 at 13:12
  • 1
    @Lundin: These seem to be multiple lines. And the partial bold face due to improper formating does not make it more readable either. User is here for >1 year and should know. – too honest for this site Sep 23 '15 at 13:14
  • @Lundin Yes but that didn't help. – eddyq Sep 25 '15 at 16:11
  • If you're trying to build an EFI executable you can't link with Visual C++ runtime at all. It only supports Windows executables. – Ross Ridge Oct 11 '15 at 05:24
  • The idea of this code is to simulate EFI by writing stubs for each EFI function. Maybe there is something in the includes that are causing this error. I'll do more checking. – eddyq Oct 19 '15 at 18:41
  • Whoever down voted my question ... I researched this as much as possible before asking the question. It is a legitimate question. Please give us the reason you down voted it. If it was simply the formatting, I didn't know that Stackoverflow would squash my paste ... I have since fixed that. Will you please remove your down vote? – eddyq Oct 22 '15 at 15:00

4 Answers4

8

If you look how vsprintf is declared you can trace it corecrt_stdio ... where it says to inline it.

I had some old DLL which were linking against old msvcrt and trying to import vsprintf from it but seems like VS2015 have new headers and trying to inline it.

Setting _NO_CRT_STDIO_INLINE helped to resolve it, Enjoy.

Edit: Also https://msdn.microsoft.com/en-us/library/bb531344.aspx

int0
  • 91
  • 2
  • 1
  • 1
    Dunno why this was downvoted.. it's valid: https://connect.microsoft.com/VisualStudio/feedback/details/1151324/memcpy-s-memmove-s-always-inline – Jon May 05 '16 at 16:32
5

You configuration appears to be incorrect. You don't seem to be linking with a couple of new libraries added in Visual Studio 2015's reorganization of the C runtime library. You also appear to linking with both the release static (/MT) and debug DLL (/MDd) version of the same library, specifically LIBCMT.lib and MSVCRTD.lib.

The symbol ___stdio_common_vsprintf_s can be found in the in Universal CRT which part of the Windows 10 SDK. The release static version of the library is called libucrt.lib. The other unresolved symbols are part of "vcruntime" library which is part of Visual Studio 2015. The name of it's release static version is libvcruntime.lib.

It not clear why you're not linking with the correct libraries. Normally this handled automatically for you. You'll need to check to your project's configuration settings to see where you've overridden the default behaviour.

Ross Ridge
  • 38,414
  • 7
  • 81
  • 112
  • 1
    I found the symbol like you said, in `ucrt.lib` in the Win10SDK. I also found the same symbol in the MSVC library directory (using dumpbin.exe on `legacy_stdio_definitions.lib`), but that one failed to resolve at link time. – SO_fix_the_vote_sorting_bug Apr 30 '21 at 15:38
1

You need insert this line

#define _NO_CRT_STDIO_INLINE
0

According to the C standard annex K

K.3.1.1 Standard headers

The functions, macros, and types declared or defined in K.3 and its subclauses are not declared or defined by their respective headers if _ _STDC_WANT_LIB_EXT1_ _ is defined as a macro which expands to the integer constant 0 at the point in the source file where the appropriate header is first included.

Meaning that in order to use the "_s" functions such as vsprintf_s, which are all found in the mentioned annex, you must define that macro to a value other than 0 before including the header files.

#define __STDC_WANT_LIB_EXT1__ 1
#include <stdarg.h>
#include <stdio.h>

I suspect that you must have a C11 compiler. Whether or not Visual Studio follows that standard, I have no idea. It is notorious for its poor standard conformance.

Lundin
  • 195,001
  • 40
  • 254
  • 396
  • Adding "__STDC_WANT_LIB_EXT1__ 1" does not help. I think there is a library that must contain _stdio_common_vsprintf_s. – eddyq Sep 23 '15 at 14:01