Help building my little SDL app on Mac OS X

I just installed the 2 Mac OS X packages (SDL-1.2.7.pkg.tar.gz and
SDL-devel-1.2.7.pkg.tar.gz) and need help getting my little app
(which uses SDL) to build. It’s just a little main.cpp plus a makefile
and it makes use of OpenGL.

I figured it should just be as simple as installing those two
Mac OS X double-clickable packages, then putting a "-framework SDL"
into my makefile, but it’s not working.

The #includes in my source file look like this:

#include
#include

#include <OpenGL/gl.h>
#include <OpenGL/glu.h>

#include <SDL.h>
#include <SDL_video.h>

and the relevant portions of my makefile look like this:

LDFLAGS = -Wall -framework OpenGL -framework SDL -framework Foundation
CPP_FLAGS = -g -c
g++ $(CPP_FLAGS) main.cpp
g++ -o $@ $(LDFLAGS) main.o

The errors I’m getting look like this:

[john ~/dev_cpp/SDL/sdl_gl_test]$ make
g++ -g -c main.cpp
main.cpp:15:17: SDL.h: No such file or directory
main.cpp:16:23: SDL_video.h: No such file or directory

I tried changing the #includes to “SDL/SDL.h” and "SDL/SDL_video.h"
but got the same errors.

As as side note, I see that the SDL package installed stuff into
/Library/Frameworks and the SDL-devel package installed stuff into
~/Library/Frameworks. It looks to me as if installing both packages
was redundant for me, since the two Mach-O dynamically linked libs
(the one in /Library/… and the one in ~/Library/…) seem to be
identical. Should I remove the one installed by the SDL package?
If so, do I just go into /Library/… and delete it, or is there
some sort of uninstall I’m supposed to do?

Thanks,
—J

John Gabriele wrote:

LDFLAGS = -Wall -framework OpenGL -framework SDL -framework Foundation
CPP_FLAGS = -g -c
g++ $(CPP_FLAGS) main.cpp
g++ -o $@ $(LDFLAGS) main.o

The errors I’m getting look like this:

[john ~/dev_cpp/SDL/sdl_gl_test]$ make
g++ -g -c main.cpp
main.cpp:15:17: SDL.h: No such file or directory
main.cpp:16:23: SDL_video.h: No such file or directory

I don’t know much about the OSX support for SDL, but the problem is
simple enough: either the header files havn’t been installed, or (as is
very likely from what I can see) the path the SDL headers are in isn’t
being searched by G++.

Try changing:

CPP_FLAGS = -g -c sdl-config --cflags
LDFLAGS = -Wall -framework OpenGL -framework SDL -framework Foundation
sdl-config --libs

Where the quotation marks used are the ones found on the same key as the
tilda (~, just left of the 1 key).

John Gabriele wrote:

LDFLAGS = -Wall -framework OpenGL -framework SDL -framework Foundation
CPP_FLAGS = -g -c
g++ $(CPP_FLAGS) main.cpp
g++ -o $@ $(LDFLAGS) main.o
The errors I’m getting look like this:
[john ~/dev_cpp/SDL/sdl_gl_test]$ make
g++ -g -c main.cpp
main.cpp:15:17: SDL.h: No such file or directory
main.cpp:16:23: SDL_video.h: No such file or directory

I don’t know much about the OSX support for SDL, but the problem is
simple enough: either the header files havn’t been installed, or (as
is very likely from what I can see) the path the SDL headers are in
isn’t being searched by G++.

Thanks for the reply Michael.

On OS X, the easy way to install SDL is to download the SDL and
SDL-devel
"packages". You unzip, then double-click these packages and they install
"frameworks" onto the system.

Poking around in ~/Library/Frameworks/SDL.framework:

[john ~/Library/Frameworks/SDL.framework]$ ls -R
Headers@ Resources@ SDL@ Versions/

./Versions:
A/ Current@

./Versions/A:
Headers/ Resources/ SDL*

./Versions/A/Headers:
SDL.h SDL_joystick.h SDL_syswm.h
SDL_active.h SDL_keyboard.h SDL_thread.h
SDL_audio.h SDL_keysym.h SDL_timer.h
SDL_byteorder.h SDL_loadso.h SDL_types.h
SDL_cdrom.h SDL_main.h SDL_version.h
SDL_copying.h SDL_mouse.h SDL_video.h
SDL_endian.h SDL_mutex.h begin_code.h
SDL_error.h SDL_opengl.h close_code.h
SDL_events.h SDL_quit.h
SDL_getenv.h SDL_rwops.h

./Versions/A/Resources:
Info.plist SDLMain.nib/

./Versions/A/Resources/SDLMain.nib:
classes.nib info.nib objects.nib

So, the header files did indeed get installed by the SDL-devel package.
They are not present in what was installed by the “runtime” SDL
package:

[john /Library/Frameworks/SDL.framework]$ ls -R
Resources@ SDL@ Versions/

./Versions:
A/ Current@

./Versions/A:
Resources/ SDL*

./Versions/A/Resources:
Info.plist SDLMain.nib/

./Versions/A/Resources/SDLMain.nib:
classes.nib info.nib objects.nib

Try changing:

CPP_FLAGS = -g -c sdl-config --cflags
LDFLAGS = -Wall -framework OpenGL -framework SDL -framework Foundation
sdl-config --libs

Where the quotation marks used are the ones found on the same key as
the tilda (~, just left of the 1 key).

I’m familiar with backquoting, however, the Mac SDL install does not
come with sdl-config. Supposedly, you’re not supposed to need it, since
Mac OS X uses the “framework” mechanism.On Nov 13, 2004, at 8:25 AM, Michael B. Edwin Rickert wrote:

John Gabriele wrote:

John Gabriele wrote:

LDFLAGS = -Wall -framework OpenGL -framework SDL -framework Foundation
CPP_FLAGS = -g -c
g++ $(CPP_FLAGS) main.cpp
g++ -o $@ $(LDFLAGS) main.o
The errors I’m getting look like this:
[john ~/dev_cpp/SDL/sdl_gl_test]$ make
g++ -g -c main.cpp
main.cpp:15:17: SDL.h: No such file or directory
main.cpp:16:23: SDL_video.h: No such file or directory

I don’t know much about the OSX support for SDL, but the problem is
simple enough: either the header files havn’t been installed, or (as
is very likely from what I can see) the path the SDL headers are in
isn’t being searched by G++.

Thanks for the reply Michael.

On OS X, the easy way to install SDL is to download the SDL and SDL-devel
"packages". You unzip, then double-click these packages and they install
"frameworks" onto the system.

Poking around in ~/Library/Frameworks/SDL.framework:

[john ~/Library/Frameworks/SDL.framework]$ ls -R
Headers@ Resources@ SDL@ Versions/

./Versions:
A/ Current@

./Versions/A:
Headers/ Resources/ SDL*

./Versions/A/Headers:
SDL.h SDL_joystick.h SDL_syswm.h
SDL_active.h SDL_keyboard.h SDL_thread.h
SDL_audio.h SDL_keysym.h SDL_timer.h
SDL_byteorder.h SDL_loadso.h SDL_types.h
SDL_cdrom.h SDL_main.h SDL_version.h
SDL_copying.h SDL_mouse.h SDL_video.h
SDL_endian.h SDL_mutex.h begin_code.h
SDL_error.h SDL_opengl.h close_code.h
SDL_events.h SDL_quit.h
SDL_getenv.h SDL_rwops.h

I’m familiar with backquoting, however, the Mac SDL install does not
come with sdl-config. Supposedly, you’re not supposed to need it, since
Mac OS X uses the “framework” mechanism.

Try adding the -framework flags into the CPPFLAGS variable as well then.
As a temporary workaround if that dosn’t work, adding
-I~/Library/Frameworks/SDL.framework/Versions/A/Headers into the
CPPFLAGS should do (manually specifying the include path yourself) to
deal with the compile-time errors.> On Nov 13, 2004, at 8:25 AM, Michael B. Edwin Rickert wrote:

Some may disagree with me, but you really should use the "unix style"
installation of SDL.

It’s very simple to install SDL via Fink (with use of the neat
FinkCommander GUI) or DarwinPorts from the command line.

http://fink.sourceforge.net/
http://darwinports.opendarwin.org/

If you installed SDL with one of these tools, then you shouldn’t need
to alter your build process at all, it will all build just as though
you were on Linux or any other Unix.

The .pkg packages are generally for working with XCode.

Try adding the -framework flags into the CPPFLAGS variable as well
then. As a temporary workaround if that dosn’t work, adding
-I~/Library/Frameworks/SDL.framework/Versions/A/Headers into the
CPPFLAGS should do (manually specifying the include path yourself) to
deal with the compile-time errors.

-framework is a linker optionOn Nov 14, 2004, at 3:10 AM, Michael B. Edwin Rickert wrote:

Try adding the -framework flags into the CPPFLAGS variable as well
then. As a temporary workaround if that dosn’t work, adding
-I~/Library/Frameworks/SDL.framework/Versions/A/Headers into the
CPPFLAGS should do (manually specifying the include path yourself) to
deal with the compile-time errors.

Tried adding “-framework SDL” to CPP_FLAGS. Didn’t with with either
#include <SDL.h> or #include <SDL/SDL.h>

Tried adding the -I~/… to CPP_FLAGS. Tried it with both SDL.h and
SDL/SDL.h. No good.On Nov 14, 2004, at 3:10 AM, Michael B. Edwin Rickert wrote:

On another note, it looks like the two Mac OS X SDL packages (SDL and SDL-devel) are redundant. I think they’re both the same, except that SDL-devel includes the headers (and goes in ~/Library instead of /Library). I thought that maybe the compiler was finding the one in /Library (with no headers) before the one in ~/Library… Removed the SDL package (in /Library) but still doesn’t work. Ok. I’m jettisoning both Mac OS X SDL packages. Unfortunately, there’s no uninstall, so I’m just trashing them. Donny wrote:

Some may disagree with me, but you really should use the "unix style"
installation of SDL.

It’s very simple to install SDL via Fink (with use of the neat
FinkCommander GUI) or DarwinPorts from the command line.

I’ve got fink installed, but “apt-cache search sdl” only offers “sdl”
(unfortunately, there’s no “sdl-devel” listed). "apt-cache show sdl"
doesn’t say anything about headers. :frowning:

I can’t make sense of that darwinports thing (I’ve heard that there’s
some sort of package management program on FreeBSD which carries the
confusing name “ports”, but I’ve got no experience with it – I guess
this is the same thing for Mac OS X). So, I’m crossing my fingers and
trying “sudo apt-get install sdl” to see what comes out.

[…time passes…]

Ok, the “sdl” package came with headers too.

I made sure my source code said SDL.h rather than SDL/SDL.h.
I appended sdl-config --libs and sdl-config --cflags in
my makefile to LDFLAGS and CPP_FLAGS, respectively.
I of course removed any mention of “-framework SDL” from my
LDFLAGS.

Ran make and it works! :slight_smile: Thanks.

BTW, FYI, my program runs in a window (not full-screen) and
prints out a little diagnostic info for me – for anyone interested,
here it is:

[john ~/dev_other/cpp/SDL/sdl_gl_test]$ ./sdl_gl_test
Found bpp = 32
*** Didn’t find hw_available. Setting vid_flags |= SDL_SWSURFACE.
*** Didn’t find blit_hw. Not setting vid_flags with SDL_HWACCEL.

------ SDL_GL_GetAttribute() info ------
SDL_GL_DOUBLEBUFFER 1
SDL_GL_RED_SIZE 8
SDL_GL_GREEN_SIZE 8
SDL_GL_BLUE_SIZE 8
SDL_GL_ALPHA_SIZE 8
SDL_GL_DEPTH_SIZE 24
SDL_GL_BUFFER_SIZE 32
SDL_GL_STENCIL_SIZE 0

------ SDL_GetVideoInfo() ------
Flag: hw_available 0
Flag: wm_available 0
UnusedBits1 0
UnusedBits2 0
Flag: blit_hw 0
Flag: blit_hw_CC 0
Flag: blit_hw_A 0
Flag: blit_sw 0
Flag: blit_sw_CC 0
Flag: blit_sw_A 0
Flag: blit_fill 0
UnusedBits3 0
video_mem 0
BitsPerPixel 32
BytesPerPixel 4

—J