mpx / lua-cjson

Lua CJSON is a fast JSON encoding/parsing module for Lua
https://kyne.au/~mark/software/lua-cjson.php
MIT License
936 stars 478 forks source link

Building with VS2015 #42

Open Jedzia opened 8 years ago

Jedzia commented 8 years ago

Don't believe it but finally, Visual Studio 14 defines snprintf()! It restricts redefinition, this is added in stdio.h:

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

so we get ...\ucrt\stdio.h(1927): fatal error C1189: #error: Macro definition of snprintf conflicts with Standard Library function declaration [...\lua-cjson\build\cjson.vcxproj errors.

My solution to this was skipping of add_definitions(-Dstrncasecmp=_strnicmp) for MSVC14. Patch follows:

CMakeLists.txt | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index ca26381..ff74d6f 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -71,8 +71,10 @@ endif()
 if(MSVC)
     add_definitions(-D_CRT_SECURE_NO_WARNINGS)
     add_definitions(-Dinline=__inline)
-    add_definitions(-Dsnprintf=_snprintf)
-    add_definitions(-Dstrncasecmp=_strnicmp)
+   if(NOT MSVC14)
+       add_definitions(-Dsnprintf=_snprintf)
+   endif(NOT MSVC14)
+   add_definitions(-Dstrncasecmp=_strnicmp)
 endif()

 add_library(cjson MODULE lua_cjson.c strbuf.c ${FPCONV_SOURCES})

Keep on coding, Jedzia;)

concatime commented 7 years ago

~~Hey, thank you! After the change, it compiled but I got this: warning: LINK : warning LNK4098: defaultlib 'LIBCMT' conflicts with use of other libs; use /NODEFAULTLIB:library It you have a simple solution to solve (and not hide) this warning, I will take it ;)~~ Wrong post, I wanted to comment on this > #44