I really wanted to install and use the Simple Directmedia Layer to begin building some game prototypes in XCode, but I kept running into the same maddening compiler errors.
Undefined symbols for architecture x86_64:
"_SDL_main", referenced from:
-[SDLMain applicationDidFinishLaunching:] in SDLMain.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I naturally searched for a solution on Google and eventually found this video, which explains how to successfully build and run a program in XCode 4 using the SDL. I generally prefer to read instructions, though, so I'm essentially going to transcribe the major steps outlined in the video for your convenience. I hope that you find this at least as helpful as I did!
Open the package and extract its contents (
SDL.framework
anddevel-lite
).Create a new project (a “Command Line Tool”), making sure to disable Automatic Reference Counting.
Drag the SDL framework that you extracted in step 2 (
SDL.framework
) into the project.Drag
SDLMain.h
andSDLMain.m
into the project from thedevel-lite
folder that you extracted in step 2.Replace
#include "SDL.h"
with#include <SDL/SDL.h>
inSDLMain.m
.Add the following
#include
's tomain.cpp
.#include <SDL/SDL.h> #include "SDLMain.h"
Make
main.cpp
an Objective-C++ file. One way to do this is to selectmain.cpp
in the Navigator, open the File Inspector in the Utilities on the right side of the XCode window, and then select “Objective-C++ Source” as the File Type. You could also simply renamemain.cpp
tomain.mm
.Change the
main
function signature to accept achar * argv[]
instead of aconst char * argv[]
.Make sure that
SDLMain.m
is compiled with the project. Select the project file in the Navigator, open the Build Phases tab, and addSDLMain.m
to the list of files under Compile Sources.Make sure that the binary is being linked with the SDL framework.
SDL.framework
should be listed under Link Binary With Libraries.Link the Cocoa and Foundation frameworks with the project's binary. Simply add
Cocoa.framework
andFoundation.framework
to the list of frameworks under Link Binary With Libraries.Build the program. This should finish successfully with a few warnings but no errors.
Build and run the program. A blank window should appear.