0

Disclaimer: Please read question carefully, This question has a twist so read it till end.

So JSON-C is one of the highly popular library to work on JSON using C programming. Basic illustration on current work, whatever code building here is for multi-platform. Currently Linux & Windows are supported platform and I have small issue with Windows related JSON-C part.

I'm using Cygwin for Windows development, and when I compile JSON-C code as per provided instruction on it's GitHub page, using CMAKE it works out quite good and build system is able generate DLLs for Windows. But if you have worked with Cygwin then you must know that whatever is built using Cygwin, will have dependency on it's run-time environment (cygwin1.dll) (Why does GCC-Windows depend on cygwin?) and it won't be an independent DLL that can be moved around to different system with same architecture. So with this dependency on Cygwin if my project is built on Windows platform, I have to carry around either Cygwin Run-Time Env. or I have to make sure Cygwin installed on target system for smooth execution. This sort of dependency I do not wish to have for my project, it can ruin user experience.

So what I want as help here, Is there a way to build JSON-C independent of Cygwin (run-time environment)??

NOTE: I already know that, if using Cygwin one wishes to create such an independent DLL for Windows then that can be done using few parameters to compiler and some additional macros placed in-front of function declaration as described here Creating a DLL in GCC or Cygwin?
But I don't see such support in source code JSON-C for Windows. So I was just wondering if JSON-C Dev team has kept some provision via build-system then I'm keen to know that part.

PS: I have not dipped into JSON-C build system yet due to my other development, so if anyone out there (my beloved community) has anything on this then please share, that would be terrific.

EDIT
Forgot to mention the version I'm using :p json-c-0.13.1-20180305

Novice
  • 540
  • 2
  • 8
  • 21

1 Answers1

0

I am able to build JSON-C 0.14-20200419 (from https://github.com/json-c/json-c) under MSYS2 with MinGW-w64 - both static and shared - using these instructions (replace /usr/local as needed):

INSTALLPREFIX=/usr/local
mkdir -p build_static build_shared &&
 cmake.exe -Wno-dev -GNinja -DCMAKE_INSTALL_PREFIX:PATH=$INSTALLPREFIX -DCMAKE_BUILD_TYPE:STRING=Release -DBUILD_SHARED_LIBS:BOOL=OFF -DBUILD_TESTING:BOOL=OFF -S. -Bbuild_static &&
 cmake.exe -Wno-dev -GNinja -DCMAKE_INSTALL_PREFIX:PATH=$INSTALLPREFIX -DCMAKE_BUILD_TYPE:STRING=Release -DBUILD_SHARED_LIBS:BOOL=ON -DBUILD_TESTING:BOOL=OFF -S. -Bbuild_shared &&
 ninja -Cbuild_static install/strip &&
 ninja -Cbuild_shared install/strip &&
 echo Success

If you don't have ninja you can probably also use -G"MSYS Makefiles" and use make instead of ninja.

Note that MinGW-w64 is different from Cygwin in that it compiles to native Windows binaries without dependancies on a compatibility layer (like Cygwin's cygwin1.dll). The following screenshots illustrates this: enter image description here

Brecht Sanders
  • 6,215
  • 1
  • 16
  • 40
  • I'm also able to build JSON-C using Cygwin, but issue is: it is coupled with Cygwin's Run-Time Environment, I want to remove that and build totally independent JSON-C lib. And you should check your built Lib with [Dependency Walker](http://www.dependencywalker.com/) to check whether it's a independent one or still requires MinGW Env at run-time. – Novice Jun 05 '20 at 10:02
  • Check this question out: [Compile a DLL in C/C++, then call it from another program](https://stackoverflow.com/questions/847396/compile-a-dll-in-c-c-then-call-it-from-another-program), you'll have more idea what I'm trying to achieve. – Novice Jun 05 '20 at 10:04
  • @Novice I wasn't talking about Cygwin. MYS2+MinGW-w64 is a different platform that generates native Windows DLL and EXE files that don't depend on an extra compatibility layer (like Cygwin's cygwin1.dll). – Brecht Sanders Jun 05 '20 at 10:06
  • Yes agree, but my question revolves around Cygwin, so this answer would be totally irrelevant. And as I have mentioned if total independence of Lib can be achieved via MinGW then I can give it thought, but for that you have to check your built (via MinGW) JSON-C Lib with dependency checker and post results here. (If using MinGW an independent JSON-C Lib can be built.) – Novice Jun 05 '20 at 10:09
  • You should really get rid of Cygwin and switch to native Windows with MinGW-w64. I have added a screenshot of Dependancy Walker above. – Brecht Sanders Jun 05 '20 at 10:15
  • Okay...Thank you for this info, let me think this through now. Then I will conclude & take the final decision. – Novice Jun 05 '20 at 10:37
  • Hi @BrechtSanders, sorry for commenting on this old conversation. Could you please tell what does `~/buildstatus.sh` script in the home directory do? This seems not part of json-c code, hence not clear what is expected in that. Thanks. – ramtech Oct 17 '21 at 18:25
  • 1
    @ramtech Sorry, forgot to remove those. I have some self-made scripts that I use in my build recipes for the https://winlibs.com/ environment that I'm working on. `~/buildstatus.sh` just shows which step of the build process is in progress. I removed them from the answer above. – Brecht Sanders Oct 18 '21 at 05:47
  • @Novice Please accept the answer if it was indeed the solution for you. – Brecht Sanders Oct 18 '21 at 05:48