Skip to content

Conversation

@kkysen
Copy link
Contributor

@kkysen kkysen commented Jun 27, 2022

Fixes #220.

As explained in #220, on macOS/BSD, #define _POSIX_C_SOURCE supersedes #define _GNU_SOURCE and prevents the GNU extension asprintf from being defined, which causes a compile error in json2cbor.c. To fix this, we can simply remove the #define _POSIX_C_SOURCE 200809L, as #define _GNU_SOURCE implies it, but without the superseding behavior seen on macOS/BSD.

Specifically, according to https://man7.org/linux/man-pages/man7/feature_test_macros.7.html,

_GNU_SOURCE
Defining this macro (with any value) implicitly defines _ATFILE_SOURCE, _LARGEFILE64_SOURCE, _ISOC99_SOURCE, _XOPEN_SOURCE_EXTENDED, _POSIX_SOURCE, _POSIX_C_SOURCE with the value 200809L (200112L in glibc versions before 2.10; 199506L in glibc versions before 2.5; 199309L in glibc versions before 2.1) and _XOPEN_SOURCE with the value 700 (600 in glibc versions before 2.10; 500 in glibc versions before 2.2). In addition, various GNU-specific extensions are also exposed.

Since glibc 2.19, defining _GNU_SOURCE also has the effect of implicitly defining _DEFAULT_SOURCE. In glibc versions before 2.20, defining _GNU_SOURCE also had the effect of implicitly defining _BSD_SOURCE and _SVID_SOURCE.

…so defined, as `_GNU_SOURCE` implicitly defines `_POSIX_C_SOURCE`, but on BSD/macOS, `_POSIX_C_SOURCE` prevents non-POSIX extensions from being defined.
@thiagomacieira
Copy link
Member

Makes sense, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants