Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++: Unresolved external symbol _sprintf and _sscanf in Visual Studio 2015

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 

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.

How should I proceed?

like image 589
NcAdams Avatar asked Sep 06 '15 00:09

NcAdams


2 Answers

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.

Your other option is to recompile the unit that depends on those functions with VS 2015 (this is probably the preferred option).

like image 181
Michael Burr Avatar answered Sep 24 '22 11:09

Michael Burr


I got this error compiling cycling max plugins against version 5 max sdk (pure c api). The legacy library fix didn't work for me (it should have, and if anyone had any idea why it mightn't I'd be curious), but I defined _NO_CRT_STDIO_INLINE before stdio was loaded and that did do the trick.

like image 27
David Karla Avatar answered Sep 24 '22 11:09

David Karla