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

C++: Unresolved external symbol _sprintf and _sscanf in Visual Studio 2015(C++:Visual Studio 2015 中未解析的外部符号 _sprintf 和 _sscanf)

本文介绍了C++:Visual Studio 2015 中未解析的外部符号 _sprintf 和 _sscanf的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于一个研究项目,我正在为科学计算语言编写 C++ 插件.不幸的是,允许用户执行此操作的库并未及时更新.

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.

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

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

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

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.

我应该如何进行?

推荐答案

将以下库添加到链接器输入文件:

Add the following library to the linker input files:

legacy_stdio_definitions.lib

VS 2015 现在使用内联定义,为许多 stdio.h 函数调用内部函数.如果目标文件(或库成员)依赖于这些函数之一,则 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.

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

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

这篇关于C++:Visual Studio 2015 中未解析的外部符号 _sprintf 和 _sscanf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:C++:Visual Studio 2015 中未解析的外部符号 _sprintf 和 _sscanf

基础教程推荐