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 1515

Summary: OS X compilation error (probably due to XInput2 changes)
Product: SDL Reporter: Gabriel Jacobo <gabomdq>
Component: *don't know*Assignee: Ryan C. Gordon <icculus>
Status: RESOLVED FIXED QA Contact: Sam Lantinga <slouken>
Severity: normal    
Priority: P2 CC: dimitris.zenios
Version: HG 2.0   
Hardware: x86   
OS: Mac OS X (All)   
Attachments: Xcode build fix

Description Gabriel Jacobo 2012-06-05 13:21:56 UTC
I'm getting a compilation error that started happening after updating my copy with the recent changes...

libtool: compile:  gcc -g -O2 -mmacosx-version-min=10.6 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.6.sdk -m32 -DUSING_GENERATED_CONFIG_H -I./include -mmmx -m3dnow -msse -msse2 -DTARGET_API_MAC_CARBON -DTARGET_API_MAC_OSX -fvisibility=hidden -I/usr/X11R6/include -D_THREAD_SAFE -falign-loops=16 -force_cpusubtype_ALL -fpascal-strings -Wall -MMD -MT build/SDL_x11events.lo -c src/video/x11/SDL_x11events.c -o build/SDL_x11events.o
In file included from src/video/x11/SDL_x11events.c:33:
src/video/x11/SDL_x11xinput2.h:30: error: conflicting types for ‘XGenericEventCookie’
/usr/X11R6/include/X11/Xlib.h:975: error: previous declaration of ‘XGenericEventCookie’ was here

/usr/X11R6/include/X11/Xlib.h:

typedef struct {
    int            type;         /* of event. Always GenericEvent */
    unsigned long  serial;       /* # of last request processed */
    Bool           send_event;   /* true if from SendEvent request */
    Display        *display;     /* Display the event was read from */
    int            extension;    /* major opcode of extension that caused the event */
    int            evtype;       /* actual event type. */
    unsigned int   cookie;
    void           *data;
} XGenericEventCookie;


src/video/x11/SDL_x11xinput2.h:

#ifndef SDL_VIDEO_DRIVER_X11_SUPPORTS_GENERIC_EVENTS
/*Define XGenericEventCookie as forward declaration when 
 *xinput2 is not available in order to compile*/
struct XGenericEventCookie;
typedef struct XGenericEventCookie XGenericEventCookie;
#endif
Comment 1 Gabriel Jacobo 2012-06-05 13:23:03 UTC
Adding Dimitris to the CC as he may know if this is related to those XInput2 changes
Comment 2 Dimitris Zenios 2012-06-05 13:36:35 UTC
This is weird since SDL_VIDEO_DRIVER_X11_SUPPORTS_GENERIC_EVENTS is defined inside SDL_config_macosx.h.Since this is defined it shouldn't enter the below path

#ifndef SDL_VIDEO_DRIVER_X11_SUPPORTS_GENERIC_EVENTS
/*Define XGenericEventCookie as forward declaration when 
 *xinput2 is not available in order to compile*/
struct XGenericEventCookie;
typedef struct XGenericEventCookie XGenericEventCookie;
#endif

To tell you the truth though,I didn't compile the changes on macosx since I don't own a pc with mac.Did you change the compilation flags or disabled anything in SDL_config_macosx.h?
Comment 3 Gabriel Jacobo 2012-06-05 13:40:42 UTC
My configure command is:

./configure --enable-silent-rules CFLAGS="-g -O2 -mmacosx-version-min=10.6 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.6.sdk -m32" LDFLAGS="-m32 -static-libgcc" --disable-shared --enable-static --prefix="some_path"

After that, make -j8, nothing fancy.
Comment 4 Dimitris Zenios 2012-06-05 13:47:38 UTC
You can also try to undef 

SDL_VIDEO_DRIVER_X11_XINPUT2 1
SDL_VIDEO_DRIVER_X11_XINPUT2_SUPPORTS_MULTITOUCH 1
SDL_VIDEO_DRIVER_X11_SUPPORTS_GENERIC_EVENTS 1 

from SDL_config_macosx.h and try compiling again to see if it works
Comment 5 Gabriel Jacobo 2012-06-05 13:49:04 UTC
Is there some test in configure to define/undefine SDL_VIDEO_DRIVER_X11_SUPPORTS_GENERIC_EVENTS ? I think my system is not using SDL_config_macosx.h but rather the autogenerated/detected header SDL_config.h, if the test is there it's failing, and if it is not there we have to add one.
Comment 6 Dimitris Zenios 2012-06-05 13:53:07 UTC
AC_CHECK_LIB(X11, XGetEventData, AC_DEFINE(SDL_VIDEO_DRIVER_X11_SUPPORTS_GENERIC_EVENTS, 1, [Have XGenericEvent]))
Comment 7 Gabriel Jacobo 2012-06-05 14:02:11 UTC
On OS X i'm getting "checking for XGetEventData in -lX11... no", I think it should be yes for SDL_VIDEO_DRIVER_X11_SUPPORTS_GENERIC_EVENTS to be defined according to the configure code.
Can this be related to the fact that you commited changes to configure.in but not to configure (AFAICT from the mercurial log) ?
Comment 8 Dimitris Zenios 2012-06-05 14:09:03 UTC
Same did autogen.sh one the next commit.Just tried it on a macosx I have and even though I get "checking for XGetEventData in -lX11... no" it compiles fine.
Comment 9 Dimitris Zenios 2012-06-05 14:11:10 UTC
Sam not Same :)
Comment 10 Gabriel Jacobo 2012-06-05 14:25:25 UTC
Yeah, I ran autoconf.sh just to see if that was the problem, but it persists. What configure/make commands are you running that are working fine on your system?
Comment 11 Dimitris Zenios 2012-06-05 14:27:41 UTC
just doing 
configure --prefix=some_prefix
make
Comment 12 Gabriel Jacobo 2012-06-05 14:48:06 UTC
I made some progress... I'm using OS X 10.7.4, if I configure with:

./configure CFLAGS="-g -O2 -m32" LDFLAGS="-m32 -static-libgcc" --disable-shared --enable-static --prefix="path"

The XGetEventData test works (result: yes) and compilation goes through fine.

But if I add 
-mmacosx-version-min=10.6 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.6.sdk 

to the configure line, the XGetEventData test fails (result: no) and compilation fails as well as reported earlier, I think this turns out to be a valid bug as this used to work before, can you verify?
Comment 13 Dimitris Zenios 2012-06-05 14:51:48 UTC
It looks like your compiling for an older mac version.I will reproduce tommorow and confirm.
Comment 14 Ryan C. Gordon 2012-06-05 23:31:16 UTC
(In reply to comment #2)
> To tell you the truth though,I didn't compile the changes on macosx since I
> don't own a pc with mac.

http://buildbot.libsdl.org/waterfall ... it shows you what the build results are for each change you push to hg.libsdl.org.

--ryan.
Comment 15 Dimitris Zenios 2012-06-06 00:11:45 UTC
Waterfall does not show any errors regarding Xinput2 on any build.It seems that the problem is when compiling for older macosx (10.6 in this case).
Comment 16 Ryan C. Gordon 2012-06-06 02:05:40 UTC
(In reply to comment #15)
> Waterfall does not show any errors regarding Xinput2 on any build.

Yeah?

http://buildbot.libsdl.org/builders/sdl-macosx-xcode/builds/306/steps/compile/logs/stdio


In file included from /buildbot/slave/SDL/sdl-macosx-xcode/src/Xcode/SDL/../../src/video/x11/SDL_x11dyn.c:27:
/buildbot/slave/SDL/sdl-macosx-xcode/src/Xcode/SDL/../../src/video/x11/SDL_x11dyn.h:57:36: error: X11/extensions/XInput2.h: No such file or directory
In file included from /buildbot/slave/SDL/sdl-macosx-xcode/src/Xcode/SDL/../../src/video/x11/SDL_x11dyn.c:110:
/buildbot/slave/SDL/sdl-macosx-xcode/src/Xcode/SDL/../../src/video/x11/SDL_x11sym.h:131: error: expected declaration specifiers or '...' before 'XGenericEventCookie'
/buildbot/slave/SDL/sdl-macosx-xcode/src/Xcode/SDL/../../src/video/x11/SDL_x11sym.h:131: error: expected declaration specifiers or '...' before 'XGenericEventCookie'

(etc.)

(The Mac OS X buildslaves are all running 10.6)

--ryan.
Comment 17 Dimitris Zenios 2012-06-06 05:42:24 UTC
Indeed.You are right.I will take a closer look tonight.
Comment 18 Dimitris Zenios 2012-06-06 10:43:18 UTC
Created attachment 872 [details]
Xcode build fix
Comment 19 Dimitris Zenios 2012-06-06 10:59:35 UTC
OK from the discussion, it seems there are two bugs.

First is when compiling the traditional way for older macosx version and the second is when compiling through Xcode.The attached patch, fixes the second problem (Some defines where wrong and also files where missing).I am still looking at the first problem 

I am on macosx 10.6.8 

and compile using the command 
../configure --enable-silent-rules CFLAGS="-g -O2 -mmacosx-version-min=10.6 -isysroot /Developer/SDKs/MacOSX10.6.sdk -m32" LDFLAGS="-m32 -static-libgcc" --disable-shared --enable-static --prefix=/Users/zenios/lib

Using the above command everything works ok.Most probably it has something to do with the newer version of macosx.From what i understand XGetEventData can not be found in the lib (SDL_VIDEO_DRIVER_X11_SUPPORTS_GENERIC_EVENTS not defined) but the headers include it. (error: previous declaration of ‘XGenericEventCookie’ was here).

Try changing in configure.in

 AC_CHECK_LIB(X11, XGetEventData, AC_DEFINE(SDL_VIDEO_DRIVER_X11_SUPPORTS_GENERIC_EVENTS, 1, [Have XGenericEvent]))

with 

            AC_MSG_CHECKING(for support generic events)
            have_generic_events=no
            AC_TRY_COMPILE([
              #include <X11/Xlib.h>
              #include <X11/Xproto.h>
              extern Bool XGetEventData(Display* a,XGenericEventCookie* b);
            ],[
            ],[
            have_generic_events=yes
            AC_DEFINE(SDL_VIDEO_DRIVER_X11_SUPPORTS_GENERIC_EVENTS)
            ])
            AC_MSG_RESULT($have_generic_events)


and retry.


Dimitris Zenios
Comment 20 Dimitris Zenios 2012-06-06 11:17:26 UTC
Looking at the bug again it seems that the problem is at the parameters you pass when compiling.

-isysroot dir
This option is like the --sysroot option, but applies only to header files. See the --sysroot option for more information. 

Maybe you have to change to

--sysroot=dir
Use dir as the logical root directory for headers and libraries. For example, if the compiler would normally search for headers in /usr/include and libraries in /usr/lib, it will instead search dir/usr/include and dir/usr/lib.
If you use both this option and the -isysroot option, then the --sysroot option will apply to libraries, but the -isysroot option will apply to header files.

The way you were compiling, you use the headers of macosx 10.6 but the libraries of macosx 10.7

Dimitris Zenios

p.s: I am not an expert when comes to macosx compiling.Comments and tips are welcome.
Comment 21 Gabriel Jacobo 2012-06-07 10:15:09 UTC
THANKS! Replacing -isysroot for --sysroot= solves the problem, feel free to close after the Xcode build fix is reviewed/accepted.
Comment 22 Gabriel Jacobo 2012-06-07 10:28:10 UTC
Amazingly, to compile for iOS I have to use -isysroot instead of --sysroot= (though I use configure/make for iOS, I overwrite the generated SDL_config.h with SDL_config_iphoneos.h ) ...sigh.

See here: http://www.cybergarage.org/twiki/bin/view/Main/IosDevTips
Comment 23 Dimitris Zenios 2012-06-07 12:38:57 UTC
I am glad that your problem was fixed.I will ping Ryan in order to check the patch for Xcode and close the bug,
Comment 24 Dimitris Zenios 2012-06-21 11:52:35 UTC
Sam fixed Xcode projects
http://hg.libsdl.org/SDL/rev/079ecfd1cde7