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

Do not define _XOPEN_SOURCE and _POSIX_C_SOURCE, when using non-POSIX features #4

Closed
marcusva opened this issue Sep 24, 2014 · 7 comments

Comments

@marcusva
Copy link

-D_POSIX_C_SOURCE=200809L -D_XOPEN_SOURCE=700 probably may cause non-Linux builds to break due to missing type definitions and functions. The switches are meant (as far as I understand the standard) to force conformance to POSIX and XSI, so everything not covered is not supposed to work until explicitly told otherwise (see http://pubs.opengroup.org/onlinepubs/007904975/functions/xsh_chap02_02.html, second section, 3rd bullet point).

Using both defines will cause FreeBSD to break building the OSS back-end due to missing u_long, u_char type definitions, since those are not covered by the standard.

/usr/bin/cc  -DAL_ALEXT_PROTOTYPES -DAL_BUILD_LIBRARY -D_GNU_SOURCE=1 -D_LARGEFILE_SOURCE -D_LARGE_FILES -D_POSIX_C_SOURCE=200809L -D_XOPEN_SOURCE=700 -Dopenal_EXPORTS -std=c99  -O2 -g -D_DEBUG -fPIC -I/home/marcus/devel/projects/extern/openal-soft/include -I/home/marcus/devel/projects/extern/openal-soft/build -I/home/marcus/devel/projects/extern/openal-soft/OpenAL32/Include -I/home/marcus/devel/projects/extern/openal-soft/Alc -I/usr/local/include    -Winline -Wall -Wextra -fvisibility=hidden -pthread -o CMakeFiles/openal.dir/Alc/backends/oss.c.o   -c /home/marcus/devel/projects/extern/openal-soft/Alc/backends/oss.c
In file included from /home/marcus/devel/projects/extern/openal-soft/Alc/backends/oss.c:41:
/usr/include/sys/soundcard.h:243:5: error: unknown type name 'u_long'; did you mean 'long'?
    u_long      play_rate;      /* sampling rate                        */
@kcat
Copy link
Owner

kcat commented Sep 25, 2014

According to that page the macro's effects are cumulative; "symbols not required or explicitly permitted [...] shall not be made visible, except when enabled by another feature test macro". So the build enables C99 (-std=c99), POSIX 2008 (-D_POSIX_C_SOURCE=200809L), and XSI 700 (-D_XOPEN_SOURCE=700). What else is needed to include sys/soundcard.h on FreeBSD?

@marcusva
Copy link
Author

sys/soundcard.h is an implementation specific detail to the OS. When it comes to OSS support, soundcard.h would be the favoured choice, since this is what the 4Front OSS documentation wants one to use. You can't rely on sys/soundcard.h, since its contents and definitions may vary from OS to OS and version to version.

sys/soundcard.h is not covered by POSIX or its XSI extension and thus left to the vendor, __BSD_VISIBLE would enable BSD-specific bits, which however may conflict with POSIX or XSI and cause undefined behaviour, if you use implementation bits of FreeBSD.

Having said all that, wouldn't it be better to

  • test for soundcard.h with POSIX/XSI enabled and
  • fall back to use sys/soundcard.h without POSIX/XSI

This also would allow people to use 4Front's official OSS implementation, which hides OS-specific bits well enough from the API interfaces.

@kcat
Copy link
Owner

kcat commented Sep 26, 2014

POSIX has to be enabled for non-Windows builds, for pthreads and such. I'm not exactly sure what XSI is needed for, though.

In either case, does changing sys/soundcard.h to soundcard.h let backends/oss.c compile?

@dscharrer
Copy link
Contributor

POSIX has to be enabled for non-Windows builds, for pthreads and such

Not on FreeBSD - there everything works without the feature macros. In my experience they are only really needed for glibc (although there may well be other *nix platforms that also need them).

I have successfully (cross-)compiled 1.16.0 for FreeBSD with the following patch:

https://github.com/arx/ArxPackages/blob/master/files/crossdev/etc/portage/mine/cross-patches/media-libs/openal/00-nongnu.patch

Note that the header for pthread_set_name_np is found in pthread_np.h, not in pthread.h.

@kcat
Copy link
Owner

kcat commented Dec 5, 2015

Can you check current master? I've tried adding a check for if _POSIX_C_SOURCE is needed (and removed the need for _XOPEN_SOURCE altogether).

@dscharrer
Copy link
Contributor

master builds fine for me without any patches with my FreeBSD cross-compiler toolchain.

@kcat
Copy link
Owner

kcat commented Dec 6, 2015

Great, then I suppose this is fixed with commit 4e6acfa. If someone's still having issues on FreeBSD, please open a new issue.

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

No branches or pull requests

3 participants