Compiling SDL for Mac
Posted: Fri Jun 10, 2011 11:42 am
Hey guys! Whilst planning to port my engine(http://www.youtube.com/user/LunarSanity?feature=mhee) to Mac I decided to run a test. Not only am I planning to port it to Mac but to port the C++ code over to Objective-C and compile using GNUstep when I'm on Windows(I like Objective-C).
My code:
Compiles fine with:
My problem occurs at runtime when I execute:
I get these runtime exceptions:
NOTE: I have no experience with Cocoa or any Mac Windowing APIs as such.
Anyone know what's wrong???
My code:
Code: Select all
#import <Foundation/Foundation.h>
#include <stdio.h>
#include <SDL/SDL.h>
#undef main
int main(int argc,char* argv[]){
NSAutoreleasePool* pool=[[NSAutoreleasePool alloc]init];
//The images
SDL_Surface* hello = NULL;
SDL_Surface* screen = NULL;
//Start SDL
SDL_Init( SDL_INIT_EVERYTHING );
//Set up screen
screen = SDL_SetVideoMode( 640, 480, 32, SDL_SWSURFACE );
//Load image
hello = SDL_LoadBMP( "hello.bmp" );
//Apply image to screen
SDL_BlitSurface( hello, NULL, screen, NULL );
//Update Screen
SDL_Flip( screen );
//Pause
SDL_Delay( 2000 );
//Free the loaded image
SDL_FreeSurface( hello );
//Quit SDL
SDL_Quit();
[pool drain];
return 0;
}
Code: Select all
Marc-Reeds-MacBook-Pro-2:documents Marc$ gcc -o Test Test.m -framework Foundation -framework SDL
Code: Select all
Marc-Reeds-MacBook-Pro-2:documents Marc$ ./Test
Code: Select all
Jun 10 17:36:37 Marc-Reeds-MacBook-Pro-2.local Test[799] <Error>: kCGErrorInvalidConnection: CGSGetCurrentCursorLocation: Invalid connection
Jun 10 17:36:37 Marc-Reeds-MacBook-Pro-2.local Test[799] <Error>: kCGErrorFailure: Set a breakpoint @ CGErrorBreakpoint() to catch errors as they are logged.
Jun 10 17:36:37 Marc-Reeds-MacBook-Pro-2.local Test[799] <Error>: kCGErrorInvalidConnection: CGSGetCurrentCursorLocation: Invalid connection
Jun 10 17:36:37 Marc-Reeds-MacBook-Pro-2.local Test[799] <Error>: kCGErrorInvalidConnection: CGSNewWindowWithOpaqueShape: Invalid connection
2011-06-10 17:36:37.761 Test[799:60b] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Error (1002) creating CGSWindow on line 262'
*** First throw call stack:
(
0 CoreFoundation 0x00007fff96763216 __exceptionPreprocess + 198
1 libobjc.A.dylib 0x00007fff9614ca2e objc_exception_throw + 43
2 CoreFoundation 0x00007fff9676304a +[NSException raise:format:arguments:] + 106
3 CoreFoundation 0x00007fff96762fd4 +[NSException raise:format:] + 116
4 AppKit 0x00007fff8f2bf084 _NSCreateWindowWithOpaqueShape2 + 788
5 AppKit 0x00007fff8f254749 -[NSWindow _commonAwake] + 1845
6 AppKit 0x00007fff8f250ebc -[NSWindow _commonInitFrame:styleMask:backing:defer:] + 1871
7 AppKit 0x00007fff8f24fbd6 -[NSWindow _initContent:styleMask:backing:defer:contentView:] + 1502
8 AppKit 0x00007fff8f24f5f2 -[NSWindow initWithContentRect:styleMask:backing:defer:] + 47
9 SDL 0x000000010055be1d SDL_SoftStretch + 24461
10 SDL 0x000000010055a57d SDL_SoftStretch + 18157
11 SDL 0x000000010054f043 SDL_SetVideoMode + 595
12 Test 0x0000000100523dc8 main + 152
13 Test 0x0000000100523d24 start + 52
14 ??? 0x0000000000000001 0x0 + 1
)
terminate called throwing an exceptionAbort trap: 6
Anyone know what's wrong???