cross-platform SDL packaging

Posts: 53
Joined: 2006.10
Post: #1

I'm on chapter 4 of Focus on SDL but I looked ahead and now I am pretty sure that this entire book is based on using VC++ >_>

Which is ok..I have VC++ and I understand everything so far but I spent yesterday night trying to figure out how to make it work without MS Windows and VC++ and I got this far:

I can compile all the samples from chapter 3 and under in linux like so:

c++ main.cpp -lSDL -o main

and it took a lot of figuring out and surfing but i finally got it to all to work on my PPC Mac OS X 10.4.9 too like so:

c++ main.cpp -lSDL -lSDLmain -framework Cocoa -o main

ok, so far great and the book says to use #include "sdl.h" with VC++ but I changed it so it is just #include "SDL/SDL.h" in VC++ because g++ in both my Linux and OS X wants "SDL/SDL.h"

Now though I know about how to make a 'bundle' well I sort of can figure it out (my IDE does it for me with wxWidgets ^_^ I am pretty sure I can figure it out) if i had to make one from scratch. And this forum helped me find the path to make universal binaries (thanks!).

but when I open Finder and command+i my binary I made in Terminal/nano it says its a PPC executable...which I understand because I didn't -arch i386 anywhere in there...

oh btw I compiled SDL myself because I couldnt find the development binaries just the runtime .dmg and the extras..but I didnt do anything with the extras

so i guess if I make a SDL app it is only PPC? How can I make it universal binary? Also, do i need to recompile my SDL as a universal binary? i guess I have to put my library of SDL inside my .app? Also, How do I do that? I don't know what the 'library' is...

I understand the MS Windows way. where i #include the SDL headers and then I link with the sdl.lib and the sdlmain.lib and Select MultiThreaded DLL with my project and then I also have to package a SDL.DLL with my game.exe

And I think I can figure out the linux way. pretty much the same but I got to package with my binary a .so I think.

But i'm not sure what is the equivalent in OS X to also giving a sdl.dll or Is it also a .so? is it one of these?

Also, one more question: What is the minimum requirement for a SDL app using just the basic SDL.h? OSX 10.2?

I hope somebody understands this...sorry for writing so much Rasp

Oops forgot to add what I'm on and using. I'm on a PPC ibook OS X 10.4.8 and using gcc and SDL latest one 1.2.11 i think whatever the latest one is..and NANO. I'm not using x-code.

gcc version 4.0.1 (Apple Computer, Inc. build 5363)

edit: Ok so I guess a 'dll' is a dynlib? on OSX

but I got a SDL.framework from the sdl.dmg so all I need to do is drag that inside my .app bundle's framework folder? or do I got to do something from scratch or something with C++ code too?

edit 2: I put sample from chapter 3_7 inside a .app bundle and it works. But i still don't know what I should be packaging with this .app for somebody that doesnt have SDL installed. and also the icon doesnt work. eventhough i changed the property in the property editor to an icon name i made and i put it in looks like a TextEdit icon kind of or some paper icon instead of my icon -.-
Quote this message in a reply
Posts: 283
Joined: 2006.05
Post: #2
mac_girl Wrote:I'm not using x-code.

Any reason you want to avoid Xcode? It would take care of *all* of those problems just by starting from the SDL Application template. But I know some people don't like Xcode.
Quote this message in a reply
Posts: 53
Joined: 2006.10
Post: #3
Quote:Any reason you want to avoid Xcode?

because I care about cross platform.

i use windows and linux just as much as i use os x. and any future apps i make will run in atleast 2 if not 3 of the platforms I actually use. xcode the little i've played with it looks nice but I don't need it and I don't use kdevelop or vc++ that much either.

i use NANO (on Windows u can install cygwin...its great!) and whatever text editor is the default if I am being lazy and if NANO isn't helpful: Kate, Notepad, TextEdit (actually sometimes i do look at C++ code in xcode and edit it a little). For my GUIs I use a cross platform IDE called DialogBlocks and i use C++ and something called wxWidgets.

I wasted enough of my time on one OS things like VB and VC++/MFC. I've learned from that and I don't want to just do the same thing in linux or OSX like Objective C/xcode or kdevelop/gtk

wxWidgets uses native widgets when it can anyways.

but that doesn't matter..the point is I want to know what to package with my bundle by hand so i can use a Lua(I'm reading a SDL book and also a Lua book at the same time ^_^ well actually and 2 other books Rasp ) script possibly when i really do it...or try and get DB to do it (doubtful the last part).

that is part of the reason why i even posted this actually. most mac people use xcode and the 'tips' on the web just say click this and click that tab in xcode...which isn't helpful to somebody that lives outside of the 'mac world' Ninja Sneaky Huh

anyways with process of elimination i will figure it out eventually Cool i'll just keep putting stuff in my bundle until i find it. But i was hoping somebody here would know how to do it without xcode helping.

not many people do crossplatform.. even in the wxwidgets forums it amazes me how many just write for Windows ... like what is the point of using a crossplatform framework if you aren't going to write for everything? But then again i gave up on FreeBSD so somebody using FBSD might look at me and be like WTH you only write for linux/MSW/OSX?! that's not _TRUE_ cross-platform! and then the NetBSD snobs look at the FreeBSD people and are all....etc.

it goes on and on forever... for ( ; ; ) { sigh(); }

I'm on chapter 6 now too. this book isn't bad besides the fact it isn't telling me how to package for non windows at all ^_^;

oh and why does my little ibook with the builtin video card support gamma (i tried the gamma sample on all my computers) but my linux and my windows doesn't! and i know they got better video cards? o.o' So it is true that apple people care about graphics more huh?
Quote this message in a reply
Posts: 245
Joined: 2005.11
Post: #4
Quote:so i guess if I make a SDL app it is only PPC? How can I make it universal binary? Also, do i need to recompile my SDL as a universal binary? i guess I have to put my library of SDL inside my .app? Also, How do I do that? I don't know what the 'library' is...
Yes, your executable and all linked libraries should be universal (if you download the runtime of SDL 1.2 it comes with a document that details how it was made). Your SDL library should be inside a folder called SDL.framework. You stick the whole thing into your .app package's Contents/Frameworks directory. I'm afraid I'm one of those non-cross-platform XCode using people so I have only the vaguest of ideas how to compile a Universal Binary from the terminal.
Quote:Also, one more question: What is the minimum requirement for a SDL app using just the basic SDL.h? OSX 10.2?
So they say. (Actually their FAQ mentions 10.1 but the docs for SDL 1.2 only seem to mention 10.2 or newer).
Quote this message in a reply
Posts: 53
Joined: 2006.10
Post: #5
So I figured it out. It's actually pretty easy but for somebody that never uses x-code it wasn't that easy but here it is for people who also are wondering how:

It turns out that there's two ways to install SDL and use SDL with Mac OS X the unix way that to me is easy and then there's the x-code way (actually I guess there's atleast a 3rd way with project builder or something?) Anyways I at first thought I got it when I really was just doing what I know and that is exactly how'd I set SDL in my Linux:

downloaded the sources and tar zxvf file.tar.gz, cd file/, ./configure, make install clean

and so I happily read my first SDL book and thought that it did this way to install and test out SDL on both my Linux and Mac.

But then I started reading my 2nd SDL book and testing on how to package SDL and I found out that this is the wrong way if you want to just release a standalone .app without making the user have to manually install SDL too.

The other way is to download the frameworks and the devel-packages they got on their site and drag them into /Library/Frameworks and ALSO (this is the part that I didn't know) read the readme with the SDL-devel dmg and drag the x-code template projects to the place the read me says then x-code magically sees it as an option and you click SDL Application

now I haven't used x-code at all other than to look quickly and maybe edit a little C++ source and even I could figure out what to do after a few minutes of playing around (that might mean x-code is pretty intuitive!) for my sample I was also using SDL_image and so I added Existing Frameworks to the Linked Frameworks part and then I also replaced main.c with main.cpp and Build + Go and then in my Release folder it...didn't work ^_^

But then I drag a copy of SDL framework and SDL image framework from /Library/Frameworks/ or wherever you put them in the bundle Frameworks/ and then it works. i tested this by removing my main copies and then moving them back so it all works.

so there are two ways to package the sdl using the same source as on linux and windows and mac!

unix way: using ANY editor and using the /usr/local/include/ <- stuff and the /usr/local/lib <- stuff

or the x-code way: using the x-code template project that comes in the devel SDL dmg and including the frameworks inside the .app bundle from /Library/Frameworks

the x-code way is easy once it's all setup correctly just change to release build and click build and the unix way you can compile via Terminal(cli) like so

# makefile for OS X and Linux
# compiling a simple SDL C++ file with SDL_image.h
# TABS are important! and those are backticks! --> `

LIBS=`sdl-config --cflags --libs`

main: main.cpp
    c++ -O2 main.cpp $(LIBS) -lSDL_image -o main

.PHONY: clean

    rm main

or some variation...this is a simple Makefile I am currectly using on Linux (I was using on Mac OS too but now that I know how to get around in x-code just enough to compile my SDL apps. I'll make them and then just use x-code to compile and drag and drop the frameworks inside the app bundle so I don't have to make the user have the .dylibs in their /usr/local/lib/ ^_^ which most non devs won't have probably.

So I hope that helps somebody also trying to figure out how to do this. I wish somebody just told me this before because it's actually pretty simple as is SDL Smile

oh and I read Focus on SDL and Programming Linux Games since my first post and i learned a lot about SDL (now to actually make a game!) Smile

edit: actually I initially suspected it was as easy as dragging the framework inside the app bundle just I didn't know I had to go through x-code to do all that... =/ But luckily x-code isn't that hard for this anyways. And yes basically this basic app is a 2.3MB universal too.

AND now I think about it it's actually nice to have the two different ways because I still find the unix way a lot easier and quicker so i can make tests and then type: make
with my own makefile and it still compiles and runs on my computer but to release to people without SDL installed I'd do the x-code template way.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Multiplayer, social and cross platform API Yespapa 0 1,943 Aug 14, 2013 02:43 AM
Last Post: Yespapa
  Cross platform library for http communication? Najdorf 2 4,283 Jan 11, 2009 01:13 PM
Last Post: Najdorf
  Cross-Platform IDE compatible w/ Scons wyrmmage 6 6,866 Mar 30, 2008 06:47 PM
Last Post: OneSadCookie
  Cross Platform System Commands wyrmmage 5 4,850 Feb 23, 2008 03:58 PM
Last Post: wyrmmage
  Cross Platform SVN Nick 10 5,863 Mar 13, 2006 07:46 AM
Last Post: nalenb