Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
kkysen opened this issue Jun 27, 2022 · 0 comments · Fixed by #221
Closed

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

kkysen opened this issue Jun 27, 2022 · 0 comments · Fixed by #221

Comments

@kkysen
Copy link
Contributor

kkysen commented Jun 27, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant