| Summary: | Warning on implicit declaration of function 'memset_pattern4' on OSX | ||
|---|---|---|---|
| Product: | SDL | Reporter: | LGB <lgblgblgb> |
| Component: | *don't know* | Assignee: | Ryan C. Gordon <icculus> |
| Status: | RESOLVED FIXED | QA Contact: | Sam Lantinga <slouken> |
| Severity: | normal | ||
| Priority: | P2 | CC: | admin, sdl-aewiesei, sezeroz |
| Version: | 2.0.12 | ||
| Hardware: | x86_64 | ||
| OS: | Mac OS X (All) | ||
Sorry, I meant "includes SDL.h" not SDL2.h. But from SDL2 :) We have the same problem in our project. It boils down to using SDL.h with POSIX features. Following is a very simple way of reproducing the issue:
echo '#include<SDL.h>' | cc -Wall -Werror=missing-prototypes -D_POSIX_C_SOURCE=200112L $(pkg-config --cflags sdl2) -x c -c -
We use POSIX features for network stuff, and we do actually also have -Werror=missing-prototypes (it's usually a source of important bugs), which makes this warning a fatal error in our case.
I got on macOS 10.15.7 with the Xcode 11.4.1 the next:
---
In file included from include/SDL2/SDL_loadso.h:44:
include/SDL2/SDL_stdinc.h:426:5: error: implicit declaration of function 'memset_pattern4' [-Werror,-Wimplicit-function-declaration]
memset_pattern4(dst, &val, dwords * 4);
^
---
And then:
---
In file included from include/SDL2/SDL_loadso.h:44:
include/SDL2/SDL_stdinc.h:426:5: error: implicit declaration of function 'memset_pattern4' [-Werror,-Wimplicit-function-declaration]
memset_pattern4(dst, &val, dwords * 4);
^
---
I had to use the latest state at the top of Mercurial. I got them as errors that broke the build of my project, not just warnings... Does it help if we define _DARWIN_C_SOURCE at top of SDL_stdinc.h? Like: diff --git a/include/SDL_stdinc.h b/include/SDL_stdinc.h --- a/include/SDL_stdinc.h +++ b/include/SDL_stdinc.h @@ -30,6 +30,10 @@ #include "SDL_config.h" +#ifdef __APPLE__ +#define _DARWIN_C_SOURCE /* for memset_pattern4() */ +#endif + #ifdef HAVE_SYS_TYPES_H #include <sys/types.h> #endif Booting my macOS machine to verify that... Nope, the error is still appear... Anyway, what I see inside: This condition blocks the necessary call: ``` #if __DARWIN_C_LEVEL >= __DARWIN_C_FULL ``` And the condition that defines the proper __DARWIN_C_LEVEL: ``` #if defined(_ANSI_SOURCE) #define __DARWIN_C_LEVEL __DARWIN_C_ANSI #elif defined(_POSIX_C_SOURCE) && !defined(_DARWIN_C_SOURCE) && !defined(_NONSTD_SOURCE) #define __DARWIN_C_LEVEL _POSIX_C_SOURCE #else #define __DARWIN_C_LEVEL __DARWIN_C_FULL #endif ``` At me I see it has _POSIX_C_SOURCE value. I am guessing that you include system headers, such as string.h, before SDL_stdinc.h (or SDL.h), meaning _DARWIN_C_SOURCE has no effect anymore. I can only suggest that you include SDL_stdinc.h (or SDL.h) before all system headers. Does it help if you do so? I'll check a bit later, however, I can point that problem does happens at here: https://github.com/WohlSoft/SDL-Mixer-X/blob/master/src/codecs/music_flac.c#L28 the "SDL_assert.h" was loaded before "SDL_loadso.h" which does include of "SDL_stdinc.h" from inside. I may guess, the mainstream SDL_mixer will get the same build error too... Probably, I will need to try define the _DARWIN_C_SOURCE globally for entire project as a small test... (In reply to Vitaly Novichkov from comment #10) > I'll check a bit later, however, I can point that problem does happens at > here: > > https://github.com/WohlSoft/SDL-Mixer-X/blob/master/src/codecs/music_flac. > c#L28 > > the "SDL_assert.h" was loaded before "SDL_loadso.h" which does include of > "SDL_stdinc.h" from inside. Because SDL_assert.h includes signal.h, and that nullifies _DARWIN_C_SOURCE That can easily be rectified by flipping the order of SDL_assert.h and SDL_loadso.h includes in music_flac.c and music_mpg123.c, if that is the only issue. I see, also music_cmd.c got affeted too, native_midi_macosx.c also. effects_internal.c, effect_stereoreserve.c, mixer.c, effect_position.c. To fix them I had to include SDL_stdinc.h at top of all of those files, or move the inclusion of SDL.h into the top of standard includes where also defined. Yeh, once I avoided those headers being included after standard headers and the library got built. I did a commit into new branch for a test and review: https://github.com/WohlSoft/SDL-Mixer-X/commit/2884d7bb387b916d0764db152f39dab00eaca44c (btw, I forgot to include mpg123 fix as I didn't use it mainly because I didn't made my CMake build for it yet, and therefore I don't use it yet. A good reminder to resume my work and finally make the CMake build for it! I have the working build for Linux, but incomplete for other platforms...) Is it just me, or does bugzilla not send notification emails again? (I got none of your replies to this bug.) > emails
Me too... It got broken again...
I pushed the _DARWIN_C_SOURCE patch from comment #6 to SDL: https://hg.libsdl.org/SDL/rev/467540bb2114 Vitaly: I pushed the following patches to SDL_mixer: https://hg.libsdl.org/SDL_mixer/rev/ec722cc63119 https://hg.libsdl.org/SDL_mixer/rev/fd0f5db8a84c https://hg.libsdl.org/SDL_mixer/rev/6b1634997479 https://hg.libsdl.org/SDL_mixer/rev/587f28c5c3eb https://hg.libsdl.org/SDL_mixer/rev/b59a761e3673 https://hg.libsdl.org/SDL_mixer/rev/e180daf91bdd Please test and tell us whether the issue is resolved. Just now I backported all fixes to MixerX, and I gonna to boot up my macOS machine to verify the fix... (In reply to Vitaly Novichkov from comment #20) > Just now I backported all fixes to MixerX, and I gonna to boot up my macOS > machine to verify the fix... For SDL_mixer side: Will mess with music_cmd.c and native_midi later. (music_cmd is practically a unix thing, but native_midi needs convert to use SDL_stdinc functions.) You missed up the "music_cmd.c" and "native_midi_macosx.c": https://github.com/WohlSoft/SDL-Mixer-X/commit/795ae1b0ac19cf767613f40795726c268e0915b2 https://github.com/WohlSoft/SDL-Mixer-X/commit/e14681cafb8c4aba2f715dd0d3cb00a0494071c6 Also, another minor unrelated fix at native_midi_macosx.c: https://github.com/WohlSoft/SDL-Mixer-X/commit/eb88f66192c70cd24042263432f9fabe9af228d2 > Will mess with music_cmd.c and native_midi later.
I had to fix that at me, and I posted my message too late...
(In reply to Vitaly Novichkov from comment #22) > You missed up the "music_cmd.c" and "native_midi_macosx.c": > > https://github.com/WohlSoft/SDL-Mixer-X/commit/ > 795ae1b0ac19cf767613f40795726c268e0915b2 > https://github.com/WohlSoft/SDL-Mixer-X/commit/ > e14681cafb8c4aba2f715dd0d3cb00a0494071c6 > > Also, another minor unrelated fix at native_midi_macosx.c: > https://github.com/WohlSoft/SDL-Mixer-X/commit/ > eb88f66192c70cd24042263432f9fabe9af228d2 https://hg.libsdl.org/SDL_mixer/rev/a094e8411283 Okay, now build the works! (I also had to patch the header at SDL 2.0.12 release copy I had to get build of my project) Seems, because of this case, all past SDL2 versions are broken for newer Xcode toolchains. (In reply to Vitaly Novichkov from comment #25) > Okay, now build the works! > > (I also had to patch the header at SDL 2.0.12 release copy I had to get > build of my project) Good. Let's hear from LGB and ux who posted complaints here. I'll possibly have to adjust other SDL projects for this, too. I applied include tweaks to SDL_net, SDL_ttf and SDL_image too: https://hg.libsdl.org/SDL_net/rev/65521c4ca248 https://hg.libsdl.org/SDL_ttf/rev/703ebc7c66fd https://hg.libsdl.org/SDL_image/rev/fec158a5ebf1 Hopefully everything should be OK. (In reply to Ozkan Sezer from comment #26) > Good. Let's hear from LGB and ux who posted complaints here. A quick test shows that the test-case I presented seems addressed, thanks. I'll probably wait for the next release to test in the real-case project though. (In reply to ux from comment #28) > A quick test shows that the test-case I presented seems addressed, thanks. > I'll probably wait for the next release to test in the real-case project > though. OK then, closing as fixed. If issues still show up, please re-open this and drop a note here. |
Recently I get C compiler warning on OSX on every file which includes SDL2.h: In file included from /usr/local/include/SDL2/SDL.h:32: In file included from /usr/local/include/SDL2/SDL_main.h:25: /usr/local/include/SDL2/SDL_stdinc.h:426:5: warning: implicit declaration of function 'memset_pattern4' is invalid in C99 [-Wimplicit-function-declaration] memset_pattern4(dst, &val, dwords * 4); ^ 1 warning generated. As far as I know (I just google'd for this), memset_pattern4() is in string.h in OSX. So I tried to include string.h before SDL.h, but interestingly the same warning ... But even if it works, I guess SDL should include the right header file for a given function by its own too. Though my project compiles regardless of the warnings, it's ugly, and may have other implications not knowing the prototype well enough by the compiler, I guess. I use Apple's "gcc" (at least they use this name) which in fact is clang: Apple clang version 11.0.0 (clang-1100.0.33.8) System info: ProductName: Mac OS X ProductVersion: 10.14.6 BuildVersion: 18G3020 SDL2 is from homebrew: ==> Downloading https://homebrew.bintray.com/bottles/sdl2-2.0.12_1.mojave.bottle.tar.gz Example build output (using travis-ci.org): https://travis-ci.org/github/lgblgblgb/xemu/jobs/678485424 Thanks for your attention!