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_Init(SDL_INIT_EVERYTHING);
SDL_SetVideoMode(640,480,32,SDL_DOUBLEBUF);
SDL_Event event;
bool isRunning = true;
while(SDL_PollEvent(&event)){
if(event.type == SDL_QUIT){
isRunning=false;
}
}
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?
I bet your
mainfunction signature is incorrect. You use:but SDL_main.h wants
Why?
You see, SDL does something really horrific when compiling: It renames your
mainfunction toSDL_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:
For more information, see Simply including SDL header causes linker error