Skip to content

json2cbor.c doesn't compile on macOS/BSD libc #220

@kkysen

Description

@kkysen

json2cbor.c doesn't compile on macOS/BSD libc with the following error:

tools/json2cbor/json2cbor.c:201:9: error: implicit declaration of function 'asprintf' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
      if (asprintf(&metadatakey, "%s%s", item->string, meta_data_marker) < 0 || metadatakey == NULL)
          ^
  1 error generated.

if (asprintf(&metadatakey, "%s%s", item->string, meta_data_marker) < 0 || metadatakey == NULL)

This happens because it defines #define _POSIX_C_SOURCE 200809L, which on some libcs, like macOS's and BSD's (I didn't test BSD, but I've seen similar issues saying the same thing), causes any non-POSIX functionality to not be declared. Thus, when #define _GNU_SOURCE is defined, which normally defines GNU extensions like asprintf, it is superseded by the #define _POSIX_C_SOURCE 200809L.

#define _POSIX_C_SOURCE 200809L
#define _GNU_SOURCE

Is the #define _POSIX_C_SOURCE 200809L needed? Without that define, I was able to compile everything. If it's not needed, I can submit a PR to remove it so it compiles on macOS and BSDs.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions