cJSON icon indicating copy to clipboard operation
cJSON copied to clipboard

Not compiling on Windows

Open mattia-moffa opened this issue 9 years ago • 8 comments

When trying to compile the library on Windows to get the shared object library, I get the following when running make all:

process_begin: CreateProcess(NULL, sh -c "uname -s 2>/dev/null || echo false", .
..) failed.
cc -c -fPIC -std=c89 -pedantic -Wall -Werror -Wstrict-prototypes -Wwrite-strings
 -Wshadow -Winit-self -Wcast-align -Wformat=2 -Wmissing-prototypes -Wstrict-over
flow=2 -Wcast-qual -Wc++-compat -Wundef -Wswitch-default -Wconversion -fstack-pr
otector-strong  cJSON.c
process_begin: CreateProcess(NULL, cc -c -fPIC -std=c89 -pedantic -Wall -Werror
-Wstrict-prototypes -Wwrite-strings -Wshadow -Winit-self -Wcast-align -Wformat=2
 -Wmissing-prototypes -Wstrict-overflow=2 -Wcast-qual -Wc++-compat -Wundef -Wswi
tch-default -Wconversion -fstack-protector-strong cJSON.c, ...) failed.
make (e=2): The system cannot find the file specified.
Makefile:68: recipe for target 'cJSON.o' failed
mingw32-make: *** [cJSON.o] Error 2

And the following with "cmake .." while in a subdir.

CMake Error at CMakeLists.txt:6 (project):
  The CMAKE_C_COMPILER:

    cl

  is not a full path and was not found in the PATH.

  To use the NMake generator with Visual C++, cmake must be run from a shell
  that can use the compiler cl from the command line.  This environment is
  unable to invoke the cl compiler.  To fix this problem, run cmake from the
  Visual Studio Command Prompt (vcvarsall.bat).

  Tell CMake where to find the compiler by setting either the environment
  variable "CC" or the CMake cache entry CMAKE_C_COMPILER to the full path to
  the compiler, or to the compiler name if it is in the PATH.


-- Configuring incomplete, errors occurred!
See also "C:/Users/Mattia/Downloads/cJSON-master/build/CMakeFiles/CMakeOutput.lo
g".
See also "C:/Users/Mattia/Downloads/cJSON-master/build/CMakeFiles/CMakeError.log
".

I'm using mingw as compiler.

mattia-moffa avatar Mar 31 '17 19:03 mattia-moffa

I never tried building cJSON on windows, I'm not familiar with the process and currently I don't have windows available (my only windows system is at home, where I am not), so maybe somebody else who already did compile it with MinGW on Windows can help you.

The Makefile doesn't support Windows, so you should definitely use CMake or compile the C-File directly.

It seems like CMake doesn't find your C compiler, so maybe you just have to set the CC environment variable to fix your problem. Not sure though.

Also you should include more information. Like how exactly did you try to compile it on Windows. Did you use msys2 for example, or some other method?

FSMaxB avatar Mar 31 '17 19:03 FSMaxB

CMake on Windows can't just use the includes.

The documentation states:

Because the entire library is only one C file and one header file, you can just copy cJSON.h and cJSON.c to your projects source and start using it.

I use Visual Studio 2015 (14,0) with CMake on Windows 10 and it fails. My code says:

#include "cJSON/cJSON.h"

It should work. Well, it doesn't:

(ClCompile Ziel) -> C:\Projects\testproject\cJSON\cJSON.c(45): error C2491: "cJSON_GetErrorPtr": Definition von Funktion für dllimport nicht zulässig [C:\Projects\testproject\rndtc.vcxproj] C:\Projects\testproject\cJSON\cJSON.c(55): error C2491: "cJSON_Version": Definition von Funktion für dllimport nicht zulässig [C:\Projects\testproject\rndtc.vcxproj] C:\Projects\testproject\cJSON\cJSON.c(114): error C2491: "cJSON_InitHooks": Definition von Funktion für dllimport nicht zulässig [C:\Projects\testproject\rndtc.vcxproj] C:\Projects\testproject\cJSON\cJSON.c(158): error C2491: "cJSON_Delete": Definition von Funktion für dllimport nicht zulässig [C:\Projects\testproject\rndtc.vcxproj] C:\Projects\testproject\cJSON\cJSON.c(220): error C2491: "cJSON_SetNumberHelper": Definition von Funktion für dllimport nicht zulässig [C:\Projects\testproject\rndtc.vcxproj] C:\Projects\testproject\cJSON\cJSON.c(847): error C2491: "cJSON_ParseWithOpts": Definition von Funktion für dllimport nicht zulässig [C:\Projects\testproject\rndtc.vcxproj] C:\Projects\testproject\cJSON\cJSON.c(887): error C2491: "cJSON_Parse": Definition von Funktion für dllimport nicht zulässig [C:\Projects\testproject\rndtc.vcxproj] C:\Projects\testproject\cJSON\cJSON.c(944): error C2491: "cJSON_Print": Definition von Funktion für dllimport nicht zulässig [C:\Projects\testproject\rndtc.vcxproj] C:\Projects\testproject\cJSON\cJSON.c(949): error C2491: "cJSON_PrintUnformatted": Definition von Funktion für dllimport nicht zulässig [C:\Projects\testproject\rndtc.vcxproj] C:\Projects\testproject\cJSON\cJSON.c(954): error C2491: "cJSON_PrintBuffered": Definition von Funktion für dllimport nicht zulässig [C:\Projects\testproject\rndtc.vcxproj] C:\Projects\testproject\cJSON\cJSON.c(981): error C2491: "cJSON_PrintPreallocated": Definition von Funktion für dllimport nicht zulässig [C:\Projects\testproject\rndtc.vcxproj] C:\Projects\testproject\cJSON\cJSON.c(1475): error C2491: "cJSON_GetArraySize": Definition von Funktion für dllimport nicht zulässig [C:\Projects\testproject\rndtc.vcxproj] C:\Projects\testproject\cJSON\cJSON.c(1490): error C2491: "cJSON_GetArrayItem": Definition von Funktion für dllimport nicht zulässig [C:\Projects\testproject\rndtc.vcxproj] C:\Projects\testproject\cJSON\cJSON.c(1502): error C2491: "cJSON_GetObjectItem": Definition von Funktion für dllimport nicht zulässig [C:\Projects\testproject\rndtc.vcxproj ] C:\Projects\testproject\cJSON\cJSON.c(1512): error C2491: "cJSON_GetObjectItemCaseSensitive": Definition von Funktion für dllimport nicht zulässig [C:\Projects\testproject\rndtc.vcxproj] C:\Projects\testproject\cJSON\cJSON.c(1530): error C2491: "cJSON_HasObjectItem": Definition von Funktion für dllimport nicht zulässig [C:\Projects\testproject\rndtc.vcxproj ] C:\Projects\testproject\cJSON\cJSON.c(1558): error C2491: "cJSON_AddItemToArray": Definition von Funktion für dllimport nicht zulässig [C:\Projects\testproject\rndtc.vcxpro j] C:\Projects\testproject\cJSON\cJSON.c(1585): error C2491: "cJSON_AddItemToObject": Definition von Funktion für dllimport nicht zulässig [C:\Projects\testproject\rndtc.vcxpr oj] C:\Projects\testproject\cJSON\cJSON.c(1598): error C2491: "cJSON_AddItemToObjectCS": Definition von Funktion für dllimport nicht zulässig [C:\Projects\testproject\rndtc.vcx proj] C:\Projects\testproject\cJSON\cJSON.c(1616): error C2491: "cJSON_AddItemReferenceToArray": Definition von Funktion für dllimport nicht zulässig [C:\Projects\testproject\rndtc.vcxproj] C:\Projects\testproject\cJSON\cJSON.c(1621): error C2491: "cJSON_AddItemReferenceToObject": Definition von Funktion für dllimport nicht zulässig [C:\Projects\testproject\rndtc.vcxproj] C:\Projects\testproject\cJSON\cJSON.c(1657): error C2491: "cJSON_DetachItemFromArray": Definition von Funktion für dllimport nicht zulässig [C:\Projects\testproject\rndtc.v cxproj] C:\Projects\testproject\cJSON\cJSON.c(1667): error C2491: "cJSON_DeleteItemFromArray": Definition von Funktion für dllimport nicht zulässig [C:\Projects\testproject\rndtc.v cxproj] C:\Projects\testproject\cJSON\cJSON.c(1672): error C2491: "cJSON_DetachItemFromObject": Definition von Funktion für dllimport nicht zulässig [C:\Projects\testproject\rndtc. vcxproj] C:\Projects\testproject\cJSON\cJSON.c(1689): error C2491: "cJSON_DeleteItemFromObject": Definition von Funktion für dllimport nicht zulässig [C:\Projects\testproject\rndtc. vcxproj] C:\Projects\testproject\cJSON\cJSON.c(1695): error C2491: "cJSON_InsertItemInArray": Definition von Funktion für dllimport nicht zulässig [C:\Projects\testproject\rndtc.vcx proj] C:\Projects\testproject\cJSON\cJSON.c(1750): error C2491: "cJSON_ReplaceItemInArray": Definition von Funktion für dllimport nicht zulässig [C:\Projects\testproject\rndtc.vc xproj] C:\Projects\testproject\cJSON\cJSON.c(1760): error C2491: "cJSON_ReplaceItemInObject": Definition von Funktion für dllimport nicht zulässig [C:\Projects\testproject\rndtc.v cxproj] C:\Projects\testproject\cJSON\cJSON.c(1783): error C2491: "cJSON_CreateNull": Definition von Funktion für dllimport nicht zulässig [C:\Projects\testproject\rndtc.vcxproj] C:\Projects\testproject\cJSON\cJSON.c(1794): error C2491: "cJSON_CreateTrue": Definition von Funktion für dllimport nicht zulässig [C:\Projects\testproject\rndtc.vcxproj] C:\Projects\testproject\cJSON\cJSON.c(1805): error C2491: "cJSON_CreateFalse": Definition von Funktion für dllimport nicht zulässig [C:\Projects\testproject\rndtc.vcxproj] C:\Projects\testproject\cJSON\cJSON.c(1816): error C2491: "cJSON_CreateBool": Definition von Funktion für dllimport nicht zulässig [C:\Projects\testproject\rndtc.vcxproj] C:\Projects\testproject\cJSON\cJSON.c(1827): error C2491: "cJSON_CreateNumber": Definition von Funktion für dllimport nicht zulässig [C:\Projects\testproject\rndtc.vcxproj] C:\Projects\testproject\cJSON\cJSON.c(1853): error C2491: "cJSON_CreateString": Definition von Funktion für dllimport nicht zulässig [C:\Projects\testproject\rndtc.vcxproj] C:\Projects\testproject\cJSON\cJSON.c(1870): error C2491: "cJSON_CreateRaw": Definition von Funktion für dllimport nicht zulässig [C:\Projects\testproject\rndtc.vcxproj] C:\Projects\testproject\cJSON\cJSON.c(1887): error C2491: "cJSON_CreateArray": Definition von Funktion für dllimport nicht zulässig [C:\Projects\testproject\rndtc.vcxproj] C:\Projects\testproject\cJSON\cJSON.c(1898): error C2491: "cJSON_CreateObject": Definition von Funktion für dllimport nicht zulässig [C:\Projects\testproject\rndtc.vcxproj] C:\Projects\testproject\cJSON\cJSON.c(1910): error C2491: "cJSON_CreateIntArray": Definition von Funktion für dllimport nicht zulässig [C:\Projects\testproject\rndtc.vcxpro j] C:\Projects\testproject\cJSON\cJSON.c(1945): error C2491: "cJSON_CreateFloatArray": Definition von Funktion für dllimport nicht zulässig [C:\Projects\testproject\rndtc.vcxp roj] C:\Projects\testproject\cJSON\cJSON.c(1981): error C2491: "cJSON_CreateDoubleArray": Definition von Funktion für dllimport nicht zulässig [C:\Projects\testproject\rndtc.vcx proj] C:\Projects\testproject\cJSON\cJSON.c(2017): error C2491: "cJSON_CreateStringArray": Definition von Funktion für dllimport nicht zulässig [C:\Projects\testproject\rndtc.vcx proj] C:\Projects\testproject\cJSON\cJSON.c(2054): error C2491: "cJSON_Duplicate": Definition von Funktion für dllimport nicht zulässig [C:\Projects\testproject\rndtc.vcxproj] C:\Projects\testproject\cJSON\cJSON.c(2133): error C2491: "cJSON_Minify": Definition von Funktion für dllimport nicht zulässig [C:\Projects\testproject\rndtc.vcxproj] C:\Projects\testproject\cJSON\cJSON.c(2197): error C2491: "cJSON_IsInvalid": Definition von Funktion für dllimport nicht zulässig [C:\Projects\testproject\rndtc.vcxproj] C:\Projects\testproject\cJSON\cJSON.c(2207): error C2491: "cJSON_IsFalse": Definition von Funktion für dllimport nicht zulässig [C:\Projects\testproject\rndtc.vcxproj] C:\Projects\testproject\cJSON\cJSON.c(2217): error C2491: "cJSON_IsTrue": Definition von Funktion für dllimport nicht zulässig [C:\Projects\testproject\rndtc.vcxproj] C:\Projects\testproject\cJSON\cJSON.c(2228): error C2491: "cJSON_IsBool": Definition von Funktion für dllimport nicht zulässig [C:\Projects\testproject\rndtc.vcxproj] C:\Projects\testproject\cJSON\cJSON.c(2237): error C2491: "cJSON_IsNull": Definition von Funktion für dllimport nicht zulässig [C:\Projects\testproject\rndtc.vcxproj] C:\Projects\testproject\cJSON\cJSON.c(2247): error C2491: "cJSON_IsNumber": Definition von Funktion für dllimport nicht zulässig [C:\Projects\testproject\rndtc.vcxproj] C:\Projects\testproject\cJSON\cJSON.c(2257): error C2491: "cJSON_IsString": Definition von Funktion für dllimport nicht zulässig [C:\Projects\testproject\rndtc.vcxproj] C:\Projects\testproject\cJSON\cJSON.c(2267): error C2491: "cJSON_IsArray": Definition von Funktion für dllimport nicht zulässig [C:\Projects\testproject\rndtc.vcxproj] C:\Projects\testproject\cJSON\cJSON.c(2277): error C2491: "cJSON_IsObject": Definition von Funktion für dllimport nicht zulässig [C:\Projects\testproject\rndtc.vcxproj] C:\Projects\testproject\cJSON\cJSON.c(2287): error C2491: "cJSON_IsRaw": Definition von Funktion für dllimport nicht zulässig [C:\Projects\testproject\rndtc.vcxproj]

Huh?

dertuxmalwieder avatar Apr 01 '17 16:04 dertuxmalwieder

ping @mjerris This might be related to the CJSON_PUBLIC macro.

FSMaxB avatar Apr 01 '17 17:04 FSMaxB

yeah it for sure is related... need to add the defines in to the build. I'll take a look this weekend and get a patch back to you. It needs the define for dllexport in the build.

mjerris avatar Apr 01 '17 17:04 mjerris

Thank you, I'll wait. :-)

dertuxmalwieder avatar Apr 01 '17 17:04 dertuxmalwieder

@dertuxmalwieder For now you only have to add the define CJSON_EXPORT_SYMBOLS and it should work.

FSMaxB avatar Apr 04 '17 18:04 FSMaxB

Confirmed, thank you. :-)

dertuxmalwieder avatar Apr 05 '17 18:04 dertuxmalwieder

Closing this because of missing response from the original reporter. (and the second issue has been solved).

FSMaxB avatar Apr 09 '17 00:04 FSMaxB