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"

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

问题描述

当我使用visual studio 2015编译cocos2d-x(版本3.3)时,发生错误:


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


源代码是:

  #ifdef snprintf 
#error snprintf的宏定义与标准库冲突
函数声明
#endif

任何人都可以告诉我出了什么问题?

解决方案

到目前为止,许多图书馆程序使用 snprintf()函数定义为 _snprintf(),因为 _snprintf

  #define snprintf _snprintf 
/ pre>

最后,Visual Studio 14定义 snprintf()



由于 snprintf()现已正式支持。我们不应该定义它。



这将覆盖stdio.h中定义的新的 snprintf()函数。

  



#ifdef snprintf
#error:snprintf的宏定义与标准库函数声明冲突
#endif

因此,你的代码不能编译。



这是真的,在所有以前的Visual Studio版本,你必须使用 _snprintf()函数。但是VS 2014以后,你不应该用 _snprintf()来定义它。



cocos 头,这是完成,因此错误。



检查并删除#define。 p>

snprintf()是C99规格的一部分。



启用C99支持



在您的程序中添加此项。

  #if _MSC_VER> = 1900 
#define STDC99
#endif

不知道_MSC_VER宏值是什么_MSC_VER宏值

  ... 
MSVC ++ 14.0 _MSC_VER == 1900
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


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

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

The source code is:

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

Anybody can tell me what's wrong?

解决方案

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

#define snprintf _snprintf

Finally, Visual Studio 14 defines snprintf()!

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

Doing it will overshadow new snprintf() function defined in 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.

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

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

Check that and remove that #define.

snprintf() is part of C99 specifications.

To enable C99 support

add this in your program

#if _MSC_VER>=1900
#  define STDC99
#endif

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天全站免登陆