11

I was going to migrate my game from glut to sdl.

It's working perfectly in glut but I wanted to use some sdl features.

So I go into my project properties, under the targets header I click the program that will be compiled, build phases, link binary with libraries, add SDL.framework

The exact same as I have done for OpenGL.framework and GLUT.framework

However when I add: #include <SDL/SDL.h> it comes up with a linker error when I try to build:

Undefined symbols for architecture x86_64:
  "_main", referenced from:
      __start in crt1.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)

Googling simply leads to a fair few results, but no real explanations.

Blam
  • 2,888
  • 3
  • 25
  • 39

2 Answers2

8

SDL uses a macro to rename your main(..) and should supply its own, usually implemented in SDLmain.m. It should be supplied together with the SDL.framework.

When you download the framework from here http://www.libsdl.org/download-1.2.php Read the ReadMeDevLite.txt in the devel-lite folder.

Another description http://www.meandmark.com/sdlopenglpart2.html

keyser
  • 18,829
  • 16
  • 59
  • 101
epatel
  • 45,805
  • 17
  • 110
  • 144
  • I'm rather new to Mac based development, not even sure what a .m file is, could you explain how I would go about sorting such things out? – Blam Aug 16 '11 at 00:03
  • 2
    @Blam, A .m file is an Objective-C file. The Mac version of SDL is written in Objective-C. Add the files SDLMain.h and SDLMain.m to your project. They contain glue code you need to compile SDL apps on Mac OS X. – Swift Dev Journal Aug 16 '11 at 18:43
2

I have found that when I get the error :

Undefined symbols for architecture x86_64:
"_main", referenced from:
implicit entry/start for main executable
(maybe you meant: _SDL_main)

I have forgotten to go to Project -> Build Phases -> Compile Sources and add SDLMain.m to the list. This solved the problem for me right away.

Andrei
  • 10,918
  • 12
  • 76
  • 110
Terry Rice
  • 494
  • 7
  • 9