William Oliver William Oliver - 1 year ago 127
C++ Question

SDL Error Undefined symbols for architecture x86_64 "_SDL_main"

I am using C++ with the SDL Cocoa and Foundation framework on my mac os x. I get the following error

Undefined symbols for architecture x86_64:
"_SDL_main", referenced from:
-[SDLMain applicationDidFinishLaunching:] in SDLMain.o
ld: symbol(s) not found for architecture x86_64

when I run the following code

#import <Foundation/Foundation.h>
#import <SDL/SDL.h>
#include "SDLMain.h"
int main(int argc, const char * argv[])
SDL_Event event;
bool isRunning = true;
if(event.type == SDL_QUIT){

return 0;

I have no idea what is wrong, although it seems that when I go into the SDLMain.m file and comment out this line of code

status = SDL_main (gArgc, gArgv);

the program compiles with no problems. However, it doesn't work. No window opens like its supposed to. Any ideas?

csl csl
Answer Source

I bet your main function signature is incorrect. You use:

int main(int argc, const char * argv[])

but SDL_main.h wants

int main(int argc, char *argv[])


You see, SDL does something really horrific when compiling: It renames your main function to SDL_main, injecting its own main function which, in turn, calls yours.

Note that if this doesn't work, then you may be compiling with wrong flags. To be sure, get the flags by typing:

$ sdl-config --cflags --libs

For more information, see Simply including SDL header causes linker error

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download