-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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] possible misuse of -D_GNU_SOURCE
(also causing warning: "_GNU_SOURCE" redefined)
#4725
Comments
It's not exactly true. $ echo | gcc -std=gnu99 -dM -E -o gnu99.txt -
$ echo | gcc -std=c99 -dM -E -o c99.txt -
$ diff c99.txt gnu99.txt | grep '<'
< #define __STRICT_ANSI__ 1
< #define __FLT32_HAS_INFINITY__ 1
$ diff c99.txt gnu99.txt | grep '>'
> #define __STDC_UTF_16__ 1
> #define unix 1
> #define __FLT32_HAS_INFINITY__ 1
> #define linux 1
> #define __STDC_UTF_32__ 1 in this case it defines
But does it change any runtime behavior though? We wanna remove |
^ edited @asdqwe |
-D_GNU_SOURCE
causing warning: "_GNU_SOURCE" redefined-D_GNU_SOURCE
(also causing warning: "_GNU_SOURCE" redefined)
# Compile rglfw module
rglfw.o : rglfw.c
- $(CC) $(GLFW_OSX) -c $< $(CFLAGS) $(INCLUDE_PATHS)
+ $(CC) $(GLFW_OSX) -c $< $(CFLAGS) $(INCLUDE_PATHS) -U_GNU_SOURCE I suspect this might be the best fix we can come up with for now |
Unfortunately there is no easy way to apply a flag to just a single file in a target in cmake as far as I can tell. Considering the warning is harmless and in a rarely edited file, it is probably not worth the effort to make it work everywhere. |
Also relevant reading for this issue: Of course, we don't control glfw so can't dictate what it does. |
Actually, CMake does not use rglfw.c so it isn't a problem there. |
Currently, a warning about _GNU_SOURCE being redefined is emitted when compiling rglfw.c In file included from rglfw.c:99: external/glfw/src/posix_poll.c:27:9: warning: "_GNU_SOURCE" redefined 27 | #define _GNU_SOURCE | ^~~~~~~~~~~ <command-line>: note: this is the location of the previous definition This can be avoided by not defining _GNU_SOURCE on the command line for this file. Defining feature test macros in source code is not really good practice so this should probably reviewed in glfw itself, at least to maybe check #ifdef _GNU_SOURCE first. But for now this change will suffice. Fixes raysan5#4725
Thanks @Peter0x44 This is so funny that GLFW defines said macro and then goes with 3 different build paths anyway, just to get correct |
Originated and partially discussed in #4720
When compiling rglfw.c from Makefile with recent versions of GCC or Clang, following warning appears:
which is happening because Makefile uses
-D_GNU_SOURCE
when compiling said source.It has been noticed that some build systems (sec/Makefile, build.zig) define
_GNU_SOURCE
at command line while others do not (Cmake) and also define different-std=c99
/-std=gnu99
which may potentially lead to inconsistencies in glibc behavior depending on build system (see comments under linked PR).Environment
Code Example
cc @Peter0x44 as discussed
The text was updated successfully, but these errors were encountered: