[jansson-users] Compiling on Windows?

1,188 views
Skip to first unread message

Twisol

unread,
Apr 19, 2010, 10:45:12 PM4/19/10
to Jansson users
Hello,

Sorry if there's an obvious answer to this, but I haven't been able to
find one. Is it possible to compile Jansson under Windows? If so, how
should I go about it?

Thanks in advance,
~Jonathan Castello

--
Jansson users mailing list
jansso...@googlegroups.com
http://groups.google.com/group/jansson-users

Petri Lehtinen

unread,
Apr 20, 2010, 2:36:33 AM4/20/10
to jansso...@googlegroups.com
Twisol wrote:
> Sorry if there's an obvious answer to this, but I haven't been able to
> find one. Is it possible to compile Jansson under Windows? If so, how
> should I go about it?

I don't use Windows so I haven't tested myself, but I've understood
that configure scripts can be run in Mingw. So the process described
in

http://www.digip.org/jansson/doc/1.2/gettingstarted.html

should work on Mingw. As it haven't been tested, it might not compile
on Windows, but it shouldn't (is not meant to) have anything not
portable to Windows.

If you don't want to use Mingw, an another option is to just compile
all *.c files under the src/ subdirectory into a library and use that.
For a DLL, global functions whose names are prefixed with "json_"
should be exported.


Petri

Jonathan Castello

unread,
Apr 20, 2010, 4:12:05 AM4/20/10
to jansso...@googlegroups.com
It doesn't seem to be quite as easy as it appears. I have to use MSVC
unfortunately, and I don't believe I can link a MingW-compiled .lib
into the project. I've tried to compile under Visual Studio 2005, and
got through most of the compilation issues with one hack or another.
Here's a list of the changes I had to make:

* Visual Studio 2005 and earlier has no stdint.h file. I grabbed one
linked from Wikipedia.
* snprintf is defined as _snprintf in VS2005. I manually added a
#define to cover that.
* The 'inline' keyword doesn't appear to be supported when compiling
as C. I #define'd 'inline' to nothing to remove it from compilation.
* In utf.h, VS was complaining about int32_t not being defined. I
added #include <stdint.h> to it to fix it.
* In several places, you use a notation that seems to be a compiler
extension. Specifically the singleton definitions for true, false, and
null, and a stream_data variable in json_loads(), all use what looks
like a keyword-based struct constructor rather than positional. E.g.:

static json_t the_true = {
.type = JSON_TRUE,
.refcount = (unsigned int)1
};

Visual Studio 2005 doesn't appear to support this. I removed the
".type =" and such, since the order seems to be the same as in the
struct definition.


After making these changes, though, I'm happy to say it does appear
work! This is great. I was using JSON-C before, but it has several
annoying bugs, and it doesn't seem to be actively maintained. I'm
happy to see that Jansson has just as simple an API, though.

Thanks for your help!
~Jonathan Castello

Jonathan Castello

unread,
Apr 20, 2010, 4:18:46 AM4/20/10
to jansso...@googlegroups.com
On Tue, Apr 20, 2010 at 1:12 AM, Jonathan Castello <twis...@gmail.com> wrote:
> After making these changes, though, I'm happy to say it does appear
> work!

It appears TO work, that is. Not to waste a post on such a trivial
thing, but I'm a stickler for fixing my typos...

~Jonathan

Petri Lehtinen

unread,
Apr 20, 2010, 4:48:14 AM4/20/10
to jansso...@googlegroups.com
Jonathan Castello wrote:
> It doesn't seem to be quite as easy as it appears. I have to use MSVC
> unfortunately, and I don't believe I can link a MingW-compiled .lib
> into the project. I've tried to compile under Visual Studio 2005, and
> got through most of the compilation issues with one hack or another.
> Here's a list of the changes I had to make:
>
> * Visual Studio 2005 and earlier has no stdint.h file. I grabbed one
> linked from Wikipedia.
> * snprintf is defined as _snprintf in VS2005. I manually added a
> #define to cover that.
> * The 'inline' keyword doesn't appear to be supported when compiling
> as C. I #define'd 'inline' to nothing to remove it from compilation.
> * In utf.h, VS was complaining about int32_t not being defined. I
> added #include <stdint.h> to it to fix it.
> * In several places, you use a notation that seems to be a compiler
> extension. Specifically the singleton definitions for true, false, and
> null, and a stream_data variable in json_loads(), all use what looks
> like a keyword-based struct constructor rather than positional. E.g.:
>
> static json_t the_true = {
> .type = JSON_TRUE,
> .refcount = (unsigned int)1
> };
>
> Visual Studio 2005 doesn't appear to support this. I removed the
> ".type =" and such, since the order seems to be the same as in the
> struct definition.

snprintf(), inline, int32_t (in stdint.h, included by inttypes.h) and
the keyword-based struct initialization form (called "designated
initializers") are C99 features. Is it possible to somehow turn on C99
in VS2005? You should need less tweaking in this case.

> After making these changes, though, I'm happy to say it does appear
> work! This is great.

Cool :)

Jonathan Castello

unread,
Apr 20, 2010, 5:16:29 AM4/20/10
to jansso...@googlegroups.com
On Tue, Apr 20, 2010 at 1:48 AM, Petri Lehtinen <pe...@digip.org> wrote:
> snprintf(), inline, int32_t (in stdint.h, included by inttypes.h) and
> the keyword-based struct initialization form (called "designated
> initializers") are C99 features. Is it possible to somehow turn on C99
> in VS2005? You should need less tweaking in this case.

Research suggests that Visual Studio doesn't fully support C99,
unfortunately, and I can't find an option for it anywhere. And Visual
Studio does support snprintf, it's just called _snprintf; I doubt C99
support would change that in particular.

stdint.h is included with VS2010, but unfortunately I'm not using that
version. Grabbing a compatible third-party stdint.h works fine though.

~Jonathan
Reply all
Reply to author
Forward
0 new messages