Wednesday, March 3, 2021

Error LNK2019 unresolved external symbol _sscanf referenced in function _GetRegistrySysColors

Error LNK2019 unresolved external symbol _sscanf referenced in function _GetRegistrySysColors@8

Template C:\Demo_Nehe\Quaternion Camera Class\glaux.lib(tk.obj) 1

  1. C++: Unresolved external symbol _sprintf and _sscanf in Visual Studio 2015
  2. For a research project, I'm writing a C++ add-on to a scientific computing language. Unfortunately the library that allows users to do this is not kept very well up-to-date.

    I started the project in XCode, where it built fine. Later I had to move to a PC, so I migrated the code to Visual Studio 2015. Since doing this, I haven't been able to build due to the following errors:

    • LNK2001 : unresolved external symbol _sprintf
    • LNK2019 : unresolved external symbol _sscanf referenced in function _GetDDouble
    • LNK2019 : unresolved external symbol _sprintf referenced in function _CheckRunningInMainThread

    The Question: An attempted fix was to add the header #define _CRT_SECURE_NO_WARNINGS. However, this a) fixed no errors and b) added the warning C4005 : '_CRT_SECURE_NO_WARNINGS': macro redefinition. I assume the library already defined this macro, anticipating this problem. Regardless, it didn't solve the problem.

    A Solution:Add the following library to the linker input files:

    legacy_stdio_definitions.lib
    VS 2015 now uses inline definitions that call internal functions for many of the stdio.h functions. If an object file (or library member) depends on one of those functions, then the legacy_stdio_definitions.lib provides an externally linkable version of the function that can be linked to.

  3. Updated to VS 2015 and now get Unresolved External Errors
  4. I have been developing in C++ in around a year now and have started development on my own game engine as a on going project this school year.

    I have decided to use GLFW and GLEW as my OpenGL libraries for this project and it worked fine in VS 2013 when I added them through Properties > VC++ Development > Include/Library Directories and Linker > Input > Additional Dependencies. But now I have made the switch to Windows 10 and VS 2015 I keep getting unresolved externals when I build which never happened before!

  5. Microsoft C/C++ change history 2003 - 2015
  6. This article describes all the breaking changes from Visual Studio 2015 going back to Visual Studio 2003, and in this article the terms "new behavior" or "now" refer to Visual Studio 2015 and later. The terms "old behavior" and "before" refer to Visual Studio 2013 and earlier releases.

    The definitions of all of the printf and scanf functions have been moved inline into , , and other CRT headers. This is a breaking change that leads to a linker error (LNK2019, unresolved external symbol) for any programs that declared these functions locally without including the appropriate CRT headers. If possible, you should update the code to include the CRT headers (that is, add #include ) and the inline functions, but if you do not want to modify your code to include these header files, an alternative solution is to add an additional library to your linker input, legacy_stdio_definitions.lib.

No comments:

Post a Comment