VS 2015编译cocos2d-x 3.3错误“致命错误C1189:#error:snprintf的宏定义与标准库函数声明冲突" [英] VS 2015 compiling cocos2d-x 3.3 error "fatal error C1189: #error: Macro definition of snprintf conflicts with Standard Library function declaration"

查看:40
本文介绍了VS 2015编译cocos2d-x 3.3错误“致命错误C1189:#error:snprintf的宏定义与标准库函数声明冲突"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用visual studio 2015编译cocos2d-x(3.3版)时,出现错误提示:

When I compile cocos2d-x (version 3.3) using visual studio 2015, an error occured, saying:

致命错误 C1189:#error:snprintf 的宏定义与标准库函数声明冲突(编译源文件 ..ases3tc.cpp)

fatal error C1189: #error: Macro definition of snprintf conflicts with Standard Library function declaration (编译源文件 ..ases3tc.cpp)

源代码为:

#ifdef snprintf
    #error Macro definition of snprintf conflicts with Standard Library 
             function declaration
#endif

谁能告诉我怎么了?

推荐答案

直到现在,许多图书馆和程序使用 snprintf() 函数,将其定义为 _snprintf(),因为支持 _snprintf().

Until now, Many libraries & programs used snprintf() function by defining it as _snprintf(), since _snprintf() was supported.

#define snprintf _snprintf

最后,Visual Studio 14 定义了 snprintf()

Finally, Visual Studio 14 defines snprintf()!

因为,现在正式支持 snprintf().我们永远不应该#define它.

Since, snprintf() is now officially supported. We should never #define it.

这样做会使 stdio.h 中定义的新 snprintf() 函数黯然失色.

Doing it will overshadow new snprintf() function defined in stdio.h.

为了限制它,它被添加到 stdio.h

To restrict that, this is added in stdio.h

#ifdef snprintf
    #error: Macro definition of snprintf conflicts with Standard Library function declaration"
#endif

因此,您的代码无法编译.

Hence, your code doesn't compile.

确实,在所有以前版本的 Visual Studio 上,您必须使用 _snprintf() 函数.但是从 VS 2014 开始,你不应该用 _snprintf() #define 它.

It is true that on all previous versions of Visual Studio, you must use _snprintf() function. But VS 2014 onwards you should not #define it with _snprintf().

在您的代码中或最有可能在 cocos 标头中的某处,已完成此操作,因此会出现错误.

Somewhere in your code or most likely in cocos headers, this is done and hence the error.

检查并删除#define.

Check that and remove that #define.

snprintf() 是 C99 规范的一部分.

snprintf() is part of C99 specifications.

启用 C99 支持

将其添加到您的程序中

#if _MSC_VER>=1900
#  define STDC99
#endif

如果您不知道 _MSC_VER 宏值是什么

In case you don't know what _MSC_VER macro values are

...
MSVC++ 14.0 _MSC_VER == 1900 (Visual Studio 2015)
MSVC++ 12.0 _MSC_VER == 1800 (Visual Studio 2013)
MSVC++ 11.0 _MSC_VER == 1700 (Visual Studio 2012)
MSVC++ 10.0 _MSC_VER == 1600 (Visual Studio 2010)
MSVC++ 9.0  _MSC_VER == 1500 (Visual Studio 2008)
MSVC++ 8.0  _MSC_VER == 1400 (Visual Studio 2005)
MSVC++ 7.1  _MSC_VER == 1310 (Visual Studio .NET 2003)
MSVC++ 7.0  _MSC_VER == 1300
MSVC++ 6.0  _MSC_VER == 1200
MSVC++ 5.0  _MSC_VER == 1100
MSVC++ 4.0  _MSC_VER == 1000
MSVC++ 2.0  _MSC_VER ==  900
MSVC++ 1.0  _MSC_VER ==  800
C/C++  7.0  _MSC_VER ==  700
C      6.0  _MSC_VER ==  600

这篇关于VS 2015编译cocos2d-x 3.3错误“致命错误C1189:#error:snprintf的宏定义与标准库函数声明冲突"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆