View Full Version : Does Anyone have a sample of SDL being implemented without Project Builder?
tingham
2003.10.06, 11:55 PM
I had posted this in another thread, replicated (paraphrased) here at the advisement of an "Elite" board member.
My problem should have a simple solution, that is, to see a working setup of SDL_init without the use of Project Builder in OSX. This project is to be written in C++.
My friend and I are beginning a new project using SDL, which needs to compile and run under both linux, windows, and osx and as such Project Builder seems like an unecessary amount of overhead.
If anyone has a simple two file setup of SDL initialization ( makefile and main.cpp ) That they can share I would be very appreciative.
Please bear in mind that I have been historically of the artistic ilk, and not very experienced with the innards of c++ or make files. Which is why I'm asking here, what I am.
original: thread (http://www.idevgames.com/forum/showthread.php?s=&threadid=4893)
Thanks for any assistance,
-thomas
OneSadCookie
2003.10.06, 11:58 PM
The examples that come with SDL can be built with a Makefile from memory...
I think you'll need the linker flags:
-framework SDL -framework OpenGL -framework Cocoa
at least, and possibly also
-framework Carbon
and/or
-framework QuickTime
tingham
2003.10.07, 12:10 AM
Where exactly would the suggested elements go?
I'm assuming the makefile, but I don't know the location within that file, nor am I familiar with the syntax.
Perhaps someone can set up a simple app to init SDL and post what they did to make it work without PB?
I feel like I'm drowning in terminology :)
Also, I wasn't able to find examples with the SDL source.. strange.
-thomas
tingham
2003.10.07, 12:42 AM
I seem to have gotten a bit further along in my process, now I'm at a very interesting stumper.
My makefile looks like:
Posted here in entirety for future help.
CC = g++
DEBUG =
OPTIZE = -O
LIBS = -lSDL -lobjc
C_FLAGS = -Wall $(DEBUG) $(OPTIZE)
SDL_LIBS = -L/usr/local/lib -lSDLmain -lSDL -framework Cocoa -framework OpenGL
UMBRA_FILES = gfxengine.o main.o
umbra: clean $(UMBRA_FILES)
$(CC) $(C_FLAGS) $(UMBRA_FILES) $(LIBS) -o ../umbra
.cpp.o:
$(CC) -c $(C_FLAGS) $<
.c.o:
$(CC) -c $(C_FLAGS) $<
clean:
rm -f *.o
rm -f ../umbra
My main.cpp includes:
#include "SDL/SDL.h"
#include "SDL/SDL_main.h"
#include "SDL/SDL_opengl.h"
and my main method is prototyped as:
int main(int argc, char * argv[]) {
When I run make, I get:
ld: Undefined symbols:
_main
I plan to edit this post once I figure out a solution to this problem. Hopefully in posterity this will be of some use to someone else.
tingham
2003.10.07, 04:19 AM
Summarily, it's quite simple, but I learned a bunch of other stuff in the process.
I'm going to post the solution, along with some other interesting factions about makefiles and using sdl with gcc or more specifically g++ as I found out later was the key to my issue.
Firstly, my main.cpp file:
#include <stdlib.h>
#include <SDL/SDL.h>
int main(int argc, char* argv[]) {
if ( SDL_Init(SDL_INIT_AUDIO|SDL_INIT_VIDEO) < 0 ) {
fprintf(stderr, "Unable to init SDL: %s\n", SDL_GetError());
exit(1);
}
atexit(SDL_Quit);
}
Note the order of includes, initially I had some trouble because I didn't have stdlib included, and then later because it came after the SDL include.
Then my makefile:
CC = g++
DEBUG = -g
OPTIMIZE = -O
LIBS = -lSDL
CFLAGS = -Wall $(DEBUG) $(OPTIMIZE)
CPPFLAGS = -Wall $(DEBUG) $(OPTIMIZE)
MY_FILES = main.o
umbra: $(MY_FILES)
$(CC) $(CFLAGS) $(MY_FILES) `sdl-config --cflags --libs` -o ../test_sdlapp
clean:
rm -f *.o
rm -f ../test_sdlapp
This will get you started working with SDL. After this you can browse the fine documentation on the sdl website (http://www.libsdl.org) to provide for setting up a surface, and entering an event loop.
This code won't add nifty items to your menu bar or any of the other things you expect from a regular SDL template Project Builder app, but it will work. You have to force quit this example to get it to stop Cmd+Option+Escape
I really hope someone else finds this useful. If so, please let me know ( I need good news )
-Thomas
Fenris
2003.10.07, 04:45 AM
Well, besides that you made an excellent post (warms my newly-appointed moderator heart), with respect to topic, acknowledgement of crossposting and to-the-point questions, I really think that info belongs in the FAQ. (Which is sadly down, but Carlos, don't purge this post until it's in the FAQ, right?)
OneSadCookie
2003.10.07, 06:02 AM
The FAQ itself is still up: http://macgamewiki.crissman.net/ -- only the links on iDev itself are broken :rolleyes:
(Incidentally, the undefined _main is because you need SDL_main.m compiled in as well. I realize you've solved this in a different way, but I thought you might be able to use that piece of knowledge).
Fenris
2003.10.07, 07:47 AM
That URL hasn't been working (at least for me) in a couple of months... :(
OneSadCookie
2003.10.07, 03:27 PM
Working fine for me...
tingham
2003.10.07, 03:38 PM
I'm not sure if these means I dun good, er not.. :)
Fenris
2003.10.07, 03:42 PM
Boy dun godd. *pats on head* :)
vBulletin® v3.6.8, Copyright ©2000-2008, Jelsoft Enterprises Ltd.