> From: Achal Oza
> I've been developing OpenGL software under Linux using the SDL
> libraries for my graduate thesis. I recently purchased my first Mac and
> I'm trying to setup my project so I can easily work on either platform
> (using #ifndef to cover any changes that are platform specific).
> Unfortunately I'm having trouble compiling my project under OS X.
If you are using SDL, the #ifndef's in your own code should be able to
be kept to a minimum. SDL does most of the nasty stuff for you.
> So far I've installed Xcode 1.5 and the SDL Development Library 1.2.8
> (Project Builder + XCode) (looks like OpenGL was included with the
> development kit). When I try creating a new Cocoa SDL OpenGL
> application, it'll compile fine.
Make sure, you installed the SDL runtime package (found on the same
page as the Development package) which it sounds like you already did
(but just to be sure). The runtime contains the SDL.framework (which
is the runtime library and header files). The development package
contains Xcode templates. (In previous SDL versions, the development
package contained header files, but I changed that to conform with
Apple framework conventions.) SDL does not install any OpenGL stuff.
That's built into to OS X.
> However when I try running the Makefile which I use in Linux, I get a
> bunch of errors. Most of them deal with not being able to locate the
> SDL and OpenGL header files. I'm not sure how to deal with this under
> the Mac environment since I'm new to the "Framework" concept (all the
> header files that I need are located in an OpenGL.framework and
> SDL.framework directories).
Yes, you will get a bunch of errors because Linux and OS X store files
in different places. The SDL/Xcode template already sets the search
paths correctly. If you use Makefiles, you have to tell it to look in
the correct paths. Furthermore, SDL recommends that you do:
#include "SDL.h"
#include "SDL_opengl.h"
and not
#include <SDL/SDL.h>
#ifdef __APPLE__
#include <OpenGL/glu.h>
#include <OpenGL/gl.h>
#else
#ifdef _WIN32
#include <windows.h>
#endif
#include <GL/glu.h>
#include <GL/gl.h
#endif
As I said, SDL already tries to hide the nasty #ifdef stuff so you
don't need to place it in your code. But it requires you to tell your
build system where things are located.
Use -I in you Makefiles to distinguish different locations for header
files. For linking to the libraries use -framework instead of -l.
So for Linux you might do (depending on which Linux dist)
gcc -I/usr/include/SDL -I/usr/include/GL testprogram.c -l SDL
-lSDLmain -lglu -lgl
For OS X you would do:
gcc -I/Library/Frameworks/SDL.framework/Headers
-I/System/Library/Frameworks/OpenGL.framework/Headers testprogram.c
SDLmain.m -framework SDL -framework OpenGL -framework Cocoa
You'll notice that you need to provide an SDLmain file instead of
linking to it, and you must link to Cocoa (because SDL is Cocoa based
on OS X). You can find SDLmain.h and SDLmain.m using the Xcode SDL
templates. Start Xcode and start a new "SDL Application" project (or
SDL OpenGL Application). You will notice that it already includes
those two files. If you bypass the SDL template, you must always
remember to copy these files into your project.
There is no sdl-config script for the framework version of SDL. You
can alternatively build SDL using configure/make or grab from Fink
which is an approach some people coming from other Unix platforms feel
more comfortable with. I personally think the framework system is
better, especially when you try running you binaries on another
machine (e.g. testing/deployment). You can easily embed the frameworks
into your application bundle, and do a drag and drop installation,
which is one of the advantages of the Mac operating system in my
opinion.
If you get tired of mucking with cross-platform build systems, I
recommend CMake. They give you a higher level scripting language
(compared to Makefiles) to express your build system and provide
prewritten scripts that find where things are located (like OpenGL and
SDL). They then generate platform native projects for you. (Makefiles,
Visual Studio, etc. Xcode is currently in development under CVS.)
Scons is another similar project, though I haven't tried it.
> I'm wondering if can specify frameworks or something like that in my
> Makefile? I apologize if this is a simple question, but I've been
> having trouble finding information about getting Linux Makefiles for
> OpenGL applications to work under OS X. Most of what I find deals with
> how to setup your project in Xcode.
You should read the SDL FAQ for more information about SDL on OS X and
SDL in general.
http://www.libsdl.org/faq.php
For a more Apple specific introduction to OpenGL on OS X, you might
want to check out "Getting Started with OpenGL in Cocoa" at
http://developer.apple.com/documentation/GraphicsImaging/Conceptual/OpenGL/
Future questions not specifically Mac-OpenGL related might be better
directed to the SDL mailing list (or other appropriate list).
Welcome to the OS X platform and good luck,
-Eric
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Mac-opengl mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/mac-opengl/email@hidden
This email sent to email@hidden