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

[build] Add -D _POSIX_C_SOURCE=200809L to CFLAGS #254

Closed
sanderboer opened this issue Apr 2, 2017 · 11 comments
Closed

[build] Add -D _POSIX_C_SOURCE=200809L to CFLAGS #254

sanderboer opened this issue Apr 2, 2017 · 11 comments
Labels
bug This is a bug platform: Web Web platform
Milestone

Comments

@sanderboer
Copy link

Hi,

I'm just starting out with raylib, the emscripten layer is what interests me.
When building raylib, make fails on an implicit function declaration. I can't seem to be able to use nanosleep() (or usleep() ) without this error popping up.
Apparently, the _POSIX_C_SOURCE macro must be defined with an appropriate value for the POSIX extensions to be available:

ifeq ($(PLATFORM),PLATFORM_WEB) CFLAGS = -D _POSIX_C_SOURCE=200809L -O1 -Wall -std=c99 -s USE_GLFW=3 -s ASSERTIONS=1 --preload-file resources #-s ALLOW_MEMORY_GROWTH=1 # to allow memory resizing #-s TOTAL_MEMORY=16777216 # to specify heap memory size (default = 16MB) endif

@raysan5
Copy link
Owner

raysan5 commented Apr 2, 2017

Hi @sanderboer, this part was changed just some days ago... Are you using develop branch?

Maybe @RDR8 could give us some feedback, it was reviewed in PR #248

@sanderboer
Copy link
Author

Hi @raysan5 ,
I just checked out the master branch...

S

@RDR8
Copy link
Contributor

RDR8 commented Apr 2, 2017

Sorry for the hiccup. Since the master branch src/Makefile is using -std=c99, -D_DEFAULT_SOURCE is the flag you want, as when compiling PLATFORM=PLATFORM_DESKTOP on Linux. Equivalent to cc -D_BSD_SOURCE -D_SVID_SOURCE -D_POSIX_C_SOURCE=200809 We need the _BSD_SOURCE for dr_flac audio.

Using -std=c99 by itself is somewhat restrictive. Refer to feature_test_macros man page

We could revert to CFLAGS = -O1 -Wall -std=gnu99 -fgnu89-inline -Wno-missing-braces if adding -D_DEFAULT_SOURCE doesn't work for @sanderboer. Doesn't make much sense though because emscipten doesn't use gcc. This applies to MacOS and even FreeBSD if someone wanted to go there.

@RDR8
Copy link
Contributor

RDR8 commented Apr 4, 2017

No idea what is actually going on here. @sanderboer is right, master is broken but the changes made to the development branch src/Makefile at 44de97e are working for me "as is" on Linux. That is, without any _SOURCE type flags. Maybe --profilng CFLAG is the diff but I don't know why the lack of it would be a problem here.

Proceeding to the examples on develop branch, most of the examples compile but I'm running into the same problem with time functions in physac as before with c99 on Linux. We probably do need -D_DEFAULT_SOURCE.

@RDR8
Copy link
Contributor

RDR8 commented Apr 4, 2017

@sanderboer If that code snippet above is in your makefile, check the syntax of -D_POSIX_C_SOURCE=200809L

@sanderboer
Copy link
Author

That code snippet is in my makefile, I added the -D_POSIX_C_SOURCE=200809L for it to compile.
Or do you mean, I'd try it with -D_DEFAULT_SOURCE instead of -D_POSIX_C_SOURCE=200809L ?

@sanderboer
Copy link
Author

Wait,
I forgot to mention, I'm building PLATFORM_WEB here, I needed to add -D_POSIX_C_SOURCE=200809L for the emscripten build.

btw. I double checked.
On the master branch I can't build PLATFORM_WEB, unless I add -D_DEFAULT_SOURCE or -D_POSIX_C_SOURCE_200809L to the CFLAGS in the Makefile.

@raysan5
Copy link
Owner

raysan5 commented Apr 4, 2017

Hi! Sorry for the broken master! Just integrated develop branch into master, it should be ok now, tried compiling for Windows and PLATFORM_WEB using Notepad++ script and it worked ok.

@RDR8
Copy link
Contributor

RDR8 commented Apr 4, 2017

@sanderboer I understand about the platform. I only mention Linux because I encountered a similiar issue there and made changes to the Makefiles recently. I think this is more of a c99 vs gnu99 issue, with each needing relevant CFLAGS. I'll update the Makefiles with options in the comments if @raysan5 already hasn't

I ask about the snippet because it has a typo. Just "no stone unturned' etc.. (^;

Do use _DEFAULT_SOURCE instead of _POSIX_C_SOURCE_200809L. According to that man page, specifying the old options alongside the new ones is only needed for old compilers that don't recognize _DEFAULT_SOURCE.

@raysan5 raysan5 changed the title PLATFORM_WEB : add -D _POSIX_C_SOURCE=200809L to CFLAGS [build] Add -D _POSIX_C_SOURCE=200809L to CFLAGS Apr 5, 2017
@raysan5 raysan5 added bug This is a bug platform: Web Web platform labels Apr 5, 2017
@raysan5 raysan5 added this to the raylib v1.7 milestone Apr 5, 2017
@RDR8
Copy link
Contributor

RDR8 commented Apr 13, 2017

This may help. #260

@raysan5
Copy link
Owner

raysan5 commented Apr 13, 2017

Reviewed in commit 82c5444

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This is a bug platform: Web Web platform
Projects
None yet
Development

No branches or pull requests

3 participants