C++: Unresolved External Symbol _Sprintf and _Sscanf in Visual Studio 2015

C++: error LNK2019: unresolved external symbol __snprintf referenced in function

Linker errors are generated due to how c++ and many other similar languages compile and link code. The compiler generates object files (*.obj) and only requires function declarations in order to compile code that calls these functions- that's why forward declarations and header files work. After compilation, at link time, the linker looks for the definitions of these functions in compiled files (usually in object files (*.obj) or libraries (*.lib). A linker error saying "Unresolved external symbol" means a declaration without matching definition has been used. Most often this is because of a spelling error in the declaration or definition, or because the file containing the definition was never linked.

Long story short, you are missing a reference to a library. That might be libcmt.lib for release and libcmtd.lib for debug.

unresolved external symbol __imp__fprintf and __imp____iob_func, SDL2

I have finally figured out why this is happening !

In visual studio 2015, stdin, stderr, stdout are defined as follow :

#define stdin  (__acrt_iob_func(0))
#define stdout (__acrt_iob_func(1))
#define stderr (__acrt_iob_func(2))

But previously, they were defined as:

#define stdin  (&__iob_func()[0])
#define stdout (&__iob_func()[1])
#define stderr (&__iob_func()[2])

So now __iob_func is not defined anymore which leads to a link error when using a .lib file compiled with previous versions of visual studio.

To solve the issue, you can try defining __iob_func() yourself which should return an array containing {*stdin,*stdout,*stderr}.

Regarding the other link errors about stdio functions (in my case it was sprintf()), you can add legacy_stdio_definitions.lib to your linker options.

eiffel c compilation failure: error LNK2001: unresolved external symbol

The compilation error when running from VS development command prompt is related to the mismatch between C compiler version and used Eiffel run-time library. Setting the corresponding environment variable before launching the compilation should fix the issue:

    set ISE_C_COMPILER=msc_vc140

As to the original error, for some reason, C compilation fails on some machines, because EiffelStudio cannot find VS. The issue has even become a FAQ.

Strtok_r unresolved external symbol

The Linux Man Pages don't provide documentation for Windows platforms. You'll need to use one of the following functions:

strtok_s, _strtok_s_l, wcstok_s, _wcstok_s_l, _mbstok_s, _mbstok_s_l

[0] https://msdn.microsoft.com/en-us/library/2c8d19sb.aspx



Related Topics



Leave a reply



Submit