C++:Visual Studio 2015 中未解析的外部符号 _sprintf 和 _sscanf

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/32418766/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-28 14:08:26  来源:igfitidea点击:

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

c++visual-studio-2015

提问by NcAdams

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.

对于一个研究项目,我正在为科学计算语言编写 C++ 插件。不幸的是,允许用户执行此操作的库并没有很好地保持最新状态。

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:

我在 XCode 中开始了这个项目,它构建得很好。后来我不得不转移到PC上,所以我将代码迁移到Visual Studio 2015。 这样做之后,由于以下错误,我一直无法构建:

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.

尝试的修复方法是添加 header #define _CRT_SECURE_NO_WARNINGS。但是,这 a) 没有修复错误,并且 b) 添加了警告C4005 : '_CRT_SECURE_NO_WARNINGS': macro redefinition。我假设库已经定义了这个宏,预料到了这个问题。无论如何,它并没有解决问题。

How should I proceed?

我应该如何进行?

回答by Michael Burr

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.hfunctions. If an object file (or library member) depends on one of those functions, then the legacy_stdio_definitions.libprovides an externally linkable version of the function that can be linked to.

VS 2015 现在使用内联定义,为许多函数调用内部stdio.h函数。如果目标文件(或库成员)依赖于这些函数之一,则legacy_stdio_definitions.lib提供可链接到的函数的外部可链接版本。

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

您的另一个选择是使用 VS 2015 重新编译依赖于这些功能的单元(这可能是首选选项)。

回答by David Karla

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.

我在编译针对版本 5 max sdk(纯 c api)的最大循环插件时遇到此错误。遗留库修复对我不起作用(它应该有,如果有人知道为什么它可能不会我会很好奇),但是我在加载 stdio 之前定义了 _NO_CRT_STDIO_INLINE 并且确实可以解决问题。