Xcode 4 - How to Install SDL on Mac OS X 10.7/10.8 Lion
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:
Open the package and extract its contents (
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.
SDLMain.minto the project from the
devel-litefolder that you extracted in step 2.
Add the following
#include <SDL/SDL.h> #include "SDLMain.h"
main.cppan Objective-C++ file. One way to do this is to select
main.cppin 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 rename
mainfunction signature to accept a
char * argvinstead of a
const char * argv.
Make sure that
SDLMain.mis compiled with the project. Select the project file in the Navigator, open the Build Phases tab, and add
SDLMain.mto the list of files under Compile Sources.
Make sure that the binary is being linked with the SDL framework.
SDL.frameworkshould be listed under Link Binary With Libraries.
Link the Cocoa and Foundation frameworks with the project’s binary. Simply add
Foundation.frameworkto 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.
I hope that you find this at least as helpful as I did!