Search code examples
cocos2d-xvisual-studio-2015

VS 2015 compiling cocos2d-x 3.6 error Macro definition of snprintf conflicts with Standard Library function declaration


I compile cocos2d-x(version 3.6) using visual studio 2015, the error occurred, saying:

fatal error C1189: #error: Macro definition of snprintf conflicts with Standard Library function declaration

Almost the same question like this link here

I try to follow the first answer and then search most results on cocos forum but also failed, I'm noob and really have no idea now ..

And here it's my source code where defined snprintf on header file stdio.h

#if defined snprintf
    // This definition of snprintf will generate "warning C4005: 'snprintf':     macro
    // redefinition" with a subsequent line indicating where the previous definition
    // of snprintf was.  This makes it easier to find where snprintf was defined.
    #pragma warning(push, 1)
    #pragma warning(1: 4005)
    #define snprintf Do not define snprintf as a macro
    #pragma warning(pop)
    #error Macro definition of snprintf conflicts with Standard Library function declaration
#endif

Could someone help me .. thanks!


Solution

  • I am getting the same error trying to build libsndfile-1. I solved it by building using VS2013 instead of VS2015. (I think it should be possible to simply install VS2013 Build Tools and build from VS2015).

    edit: to install the VS2013 build toolset, run the VS2015 installer and select 'Windows 8.1 and Windows Phone 8.0/8.1 Tools'