66

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?

asked Sep 6, 2015 at 0:00
2
  • I answered this exact question here with enough details and references. Commented Aug 22, 2024 at 6:23
  • feel free to ask if something went unexpectedly Commented Aug 22, 2024 at 6:49

3 Answers 3

197

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).

answered Sep 6, 2015 at 0:28
Sign up to request clarification or add additional context in comments.

8 Comments

@user4581301: can you elaborate?
Sorry. Supporting, even if with a wrapper, the old stdio stuff without wailing and moaning. Every now and then snprintf is exactly the right tool for the job, and I hate having to do portability wrappers for something that should just come in the box.
@Epirocks: I haven't tested that myself yet - are you using the lib from C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\lib\amd64? What are some of the exact error messages you get?
No, x64 but in the end the errors were coming from a separate library which has been replaced by the vendor, so disregard what I said, thanks.
You could also add: #pragma comment (lib, "legacy_stdio_definitions.lib") into one of the source files to have it added by the linker as well.
|
3

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.

answered May 27, 2017 at 20:07

Comments

0

I recently encountered this and was able to add User32.lib to Linker > Input > Additional Dependencies.

You could also include #pragma comment (lib, "User32.lib") in your code.

answered Nov 22, 2021 at 23:53

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.