We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 1328

Summary: SDL conflicts with stdint.h and shouldn't
Product: SDL Reporter: Ellie <etc0de>
Component: *don't know*Assignee: Ryan C. Gordon <icculus>
Status: RESOLVED FIXED QA Contact: Sam Lantinga <slouken>
Severity: normal    
Priority: P2    
Version: HG 2.0   
Hardware: x86   
OS: Linux   

Description Ellie 2011-11-08 02:24:19 UTC
SDL conflicts with stdint.h, and IMHO for being able to write sane programs that use stdint.h properly but also use SDL at times, it shouldn't.

Example (on Fedora 16):
In file included from /usr/lib/gcc/i686-redhat-linux/4.6.2/include/stdint.h:3:0,
                 from /usr/include/inttypes.h:28,
                 from sdl/include/SDL_stdinc.h:67,
                 from sdl/include/SDL_main.h:25,
                 from sdl/include/SDL.h:72,
                 from graphics.c:24:
/usr/include/stdint.h:129:23: error: conflicting types for ‘uintptr_t’
sdl/include/SDL_config_minimal.h:46:23: note: previous declaration of ‘uintptr_t’ was here

I think SDL either should only internally define its standard stuff and offer it to the user only when not already available through stdint.h (or when the user wants to have it explicitely), or it should simply not conflict with the official standard header file stdint.h.
Comment 1 Ellie 2011-11-08 02:25:24 UTC
See also here why forcing possibly incompatible standard type definitions onto the user might be a bad idea:

http://www.gamedev.net/topic/531286-stdinth-and-library-conflicts/
Comment 2 Ellie 2011-11-08 02:30:35 UTC
It seems to be another problem actually: SDL includes <stdint.h> itself internally, and this then clashes with its own headers.

Does it help you when I upload the stdint.h present on my system somewhere?
Comment 3 Ryan C. Gordon 2011-11-16 02:00:49 UTC
The problem appears to be that you're using SDL_config_minimal.h, instead of a system-specific SDL_config.h, generated at build time by SDL's configure script.

Where did these headers come from?

--ryan.
Comment 4 Ellie 2011-11-16 02:26:58 UTC
I simply did ./configure && make as usual on a git SDL 1.3, and then set the include dir to that SDL's include/ folder (gcc option). Then I simply did #include "SDL/SDL.h" in the application.

When I had the include path previously set to that SDL's include/SDL instead of that SDL's include/ I got an include error, so I think it is indeed grabbing it from the right folder and not somewhere else (system headers or so).
Comment 5 Ellie 2011-12-20 23:11:46 UTC
Was this issue resolved? I compiled against the unmodified latest hg version today and it seems to be gone.

Well, maybe it was also an issue with Fedora's headers with a fix on their side...
Comment 6 Ellie 2012-01-01 20:16:38 UTC
I am not sure if I am supposed to do this, but for the sake of a clean bugzilla and in the light of this bug being totally gone in my configuration where I initially saw it, I will put this bug as resolved. If that is something I shouldn't have done, please revert/reopen.
Comment 7 Ellie 2012-02-05 11:48:07 UTC
I just ran into this again, and this time located the problem:

/usr/include/stdint.h defines _STDINT_H
But SDL_config_minimal.h checks only for _STDINT_H_.

Fix:
----

Replace SDL_config_minimal.h:36
#if !defined(_STDINT_H_) && (!defined(HAVE_STDINT_H) || !_HAVE_STDINT_H)
with
#if !defined(_STDINT_H_) && !defined(_STDINT_H) && (!defined(HAVE_STDINT_H) || !_HAVE_STDINT_H)
Comment 8 Ryan C. Gordon 2012-02-06 21:29:30 UTC
> Replace SDL_config_minimal.h:36

I'll fix this, but to be clear: you shouldn't be using SDL_config_minimal.h ... the configure script should have generated a very-detailed SDL_config.h that's specific to the features available on your machine...the "minimal" version is there as a fallback for systems that don't use configure.

If this was an accident, we should figure out why you ended up with the wrong SDL_config*.h header.

--ryan.
Comment 9 Ellie 2012-02-06 22:27:14 UTC
I used a freshly checked out SDL2 with only the RenderCopyEx patch applied of which I'm pretty sure it wouldn't touch any related things.

Then I did configure and make and ended up with the given error.
Comment 10 Ryan C. Gordon 2012-02-06 22:31:06 UTC
(In reply to comment #7)
> Replace SDL_config_minimal.h:36

This now checks for _STDINT_H, as of hg changeset 2c2ebbcb1980.

--ryan.
Comment 11 Ryan C. Gordon 2012-02-06 22:32:06 UTC
(In reply to comment #9)
> Then I did configure and make and ended up with the given error.

The error was during the make step?

--ryan.
Comment 12 Ellie 2012-02-06 23:04:05 UTC
The compiler parsed the SDL.h include while compiling my application and then ended up with the given redefinition conflict traced back to SDL_config_minimal.h.

It was during the make step of my application, not the one of SDL. That one went fine, only compiling my app afterwards failed.
Comment 13 Ryan C. Gordon 2012-02-07 12:25:25 UTC
(In reply to comment #12)
> It was during the make step of my application, not the one of SDL. That one
> went fine, only compiling my app afterwards failed.

And did you point your application directly at SDL's "include" directory, or the headers that were installed by "make install"?

SDL_config.h is (over)written by the configure script, and if you built in a separate directory, the default one in SDL/include is not the right header.

(However, this code has changed recently, so this could be our bug, too.)

--ryan.
Comment 14 Ellie 2012-02-07 12:34:00 UTC
I point it to SDL's include/ folder. I don't make install SDL, I only make it and I removed its .hg folder to avoid that error that tells me to build somewhere else to avoid changing my hg'ed headers. I recheckout for every new SDL revision I am interested in anyway, so I don't care for changed headers - I do not use that particular SDL2 copy for commits.

Should I attach my SDL_config.h, the config.log or anything else?
Comment 15 Ryan C. Gordon 2013-07-05 01:23:21 UTC
This _should_ be fixed as of this changeset:

    http://hg.libsdl.org/SDL/rev/5d6b7b9432d3

Please reopen if it's still broken for you.

Thanks!

--ryan.