Hey,
I wanted to build this little example SDL program:
http://friedspace.com/SDLTest.c
I saved this a file called sdl.c. On my GNU/Linux box I had no trouble. This,
GNU/Linux$ gcc -I/usr/include/SDL -L/usr/lib sdl.c -lSDL
produces a viable executable. On OS X there are these framework things. I don't know much about them, but they appear to contain all of what is necessary to compile and link a program against, say, SDL. So I installed the SDL framework from
http://www.libsdl.org/download-1.2.php (I just copied SDL.framework into /Library/Frameworks) and tried to build the same sample program via:
smithzv@belial:[0]:~/src/work/sdl-examples$ gcc sdl.c -framework SDL
sdl.c:3:16: error: SDL.h: No such file or directory
sdl.c:10: error: parse error before '*' token
sdl.c: In function 'setpixel':
sdl.c:12: error: 'Uint32' undeclared (first use in this function)
sdl.c:12: error: (Each undeclared identifier is reported only once
sdl.c:12: error: for each function it appears in.)
sdl.c:12: error: 'pixmem32' undeclared (first use in this function)
sdl.c:13: error: parse error before 'colour'
sdl.c:15: error: 'colour' undeclared (first use in this function)
sdl.c:15: error: 'screen' undeclared (first use in this function)
sdl.c:15: error: 'r' undeclared (first use in this function)
sdl.c:15: error: 'g' undeclared (first use in this function)
sdl.c:15: error: 'b' undeclared (first use in this function)
sdl.c:17: error: parse error before ')' token
sdl.c: At top level:
sdl.c:22: error: parse error before '*' token
sdl.c: In function 'DrawScreen':
sdl.c:26: error: 'screen' undeclared (first use in this function)
sdl.c:36: error: 'h' undeclared (first use in this function)
sdl.c: In function 'main':
sdl.c:48: error: 'SDL_Surface' undeclared (first use in this function)
sdl.c:48: error: 'screen' undeclared (first use in this function)
sdl.c:49: error: 'SDL_Event' undeclared (first use in this function)
sdl.c:49: error: parse error before 'event'
sdl.c:54: error: 'SDL_INIT_VIDEO' undeclared (first use in this function)
sdl.c:56: error: 'SDL_FULLSCREEN' undeclared (first use in this function)
sdl.c:56: error: 'SDL_HWSURFACE' undeclared (first use in this function)
sdl.c:65: error: 'event' undeclared (first use in this function)
sdl.c:69: error: 'SDL_QUIT' undeclared (first use in this function)
sdl.c:72: error: 'SDL_KEYDOWN' undeclared (first use in this function)
Okay, it cannot find the header files. I tried adding a -F/Library/Frameworks to the options but it made no difference. I tried explicitly compiling and the linking passing the framework option to the linker by hand:
smithzv@belial:[0]:~/src/work/sdl-examples$ gcc -c sdl.c -I/Library/Frameworks/SDL.framework/Headers
smithzv@belial:[0]:~/src/work/sdl-examples$ ld -framework SDL sdl.o
ld: /Library/Frameworks/SDL.framework/SDL load command 6 unknown cmd field
...still no go. I also thought that maybe I could get around the frameworks if I installed SDL through MacPorts, which I did. So I tried this (my MacPorts tree is in the default /opt/local):
smithzv@belial:[0]:~/src/work/sdl-examples$ gcc -c sdl.c -I/opt/local/include/SDL
smithzv@belial:[0]:~/src/work/sdl-examples$ gcc sdl.o -L/opt/local/lib -lSDL
/usr/bin/ld: Undefined symbols:
_main
collect2: ld returned 1 exit status
Hmmm... okay, let's check...
smithzv@belial:[0]:~/src/work/sdl-examples$ nm sdl.o
0000006c T _DrawScreen
U _SDL_Flip
U _SDL_Init
U _SDL_LockSurface
U _SDL_MapRGB
U _SDL_PollEvent
U _SDL_Quit
U _SDL_SetVideoMode
U _SDL_UnlockSurface
000001cb T _SDL_main
00000000 T _setpixel
...sure enough, no main symbol. For comparison, on the linux box...
GNU/Linux$ nm sdl.o
0000006f T DrawScreen
U SDL_Flip
U SDL_Init
U SDL_LockSurface
U SDL_MapRGB
U SDL_PollEvent
U SDL_Quit
U SDL_SetVideoMode
U SDL_UnlockSurface
000001cc T main
00000000 T setpixel
...we do get a main function.
Any thoughts on what I am doing wrong? I have reinstalled the SDL framework, but this had no effect.
Thanks for any hints,
Zach
BTW I have had a hard time finding much help on developing in OS X. If anyone has some links, I would love to check them out.