Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting up SDL on Mac OS X Lion with Xcode 4

I've been trying to get a super simple SDL program to work. I'm using Mac OS X Lion. I've got SDL to work in Snow Leopard, but it doesn't seem to want to work in lion. So far I have this:

#include <iostream>
#include "SDL/SDL.h"

using namespace std;

/*
#ifdef main
#  undef main
#endif
*/

int main( int argc, char* args[] )
{
    SDL_Surface* hello = NULL;
    SDL_Surface* screen = NULL;
    SDL_Init( SDL_INIT_EVERYTHING );
    screen = SDL_SetVideoMode( 640, 480, 32, SDL_SWSURFACE );
    hello = SDL_LoadBMP( "hello.bmp" );
    SDL_BlitSurface( hello, NULL, screen, NULL );
    SDL_Flip( screen );
    SDL_Delay( 2000 );
    SDL_FreeSurface( hello );
    SDL_Quit();

    return 0;
}

When I try to compile this code (in Xcode 4.1) it gives me this error:

Undefined symbols for architecture x86_64:
  "_main", referenced from:
      start in crt1.10.6.o
     (maybe you meant: _SDL_main)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

If I uncomment the #ifdef stuff I have commented currently, the program compiles, but then receives SIGABRT on the SDL_SetVideoMode line. That commented stuff I have I just saw in another program, I'm not sure if I'm supposed to have it or not.

How am I supposed to get this working?

like image 213
Cole Avatar asked Nov 22 '11 02:11

Cole


People also ask

Does SDL work on Mac?

What is supported? SDL 2.0. 0 supports Mac OS X 10.5 and newer, using either Xcode or the classic Unix-style build system. Currently only Xcode can be used to build the SDL Framework.


1 Answers

The SDL header files redefine main with a macro. This is in SDL_main.h:

#define main    SDL_main

But this is fine. SDL provides its own main() function that then calls your version. So get rid of those defines, they are making it worse, not better.

If your project is Cocoa based, then you probably missed to include SDLmain.m in your project. This provides a Cocoa friendly main() function. If your project is native C++, then my guess is that you did not include all the SDL libs in your project, so the linker isn't seeing SDL's own main().

like image 56
Miguel Avatar answered Sep 30 '22 14:09

Miguel