eddyq
eddyq

Reputation: 909

Unresolved ___stdio_common_vsprintf_s, what library has this?

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 

Upvotes: 5

Views: 33155

Answers (4)

Huy võ lê
Huy võ lê

Reputation: 31

You need insert this line

#define _NO_CRT_STDIO_INLINE

Upvotes: 2

int0
int0

Reputation: 101

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

Upvotes: 9

Ross Ridge
Ross Ridge

Reputation: 39621

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.

Upvotes: 6

Lundin
Lundin

Reputation: 214395

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.

Upvotes: 0

Related Questions