Skip to content

Instantly share code, notes, and snippets.

@nddrylliog
Created November 15, 2012 02:03
Show Gist options
  • Save nddrylliog/4076182 to your computer and use it in GitHub Desktop.
Save nddrylliog/4076182 to your computer and use it in GitHub Desktop.
Notes on getting SDL ooc stuff to compile on all three platforms

What is this?

These are notes on how to get ooc-sdl samples to compile & run on all three platforms.

Linux

Smooth sailing. You can bootstrap rock easily, just clone the git repository then run make rescue:

cd ~/Dev/
git clone git://github.com/nddrylliog/rock.git
cd rock
make rescue

Then get rock in your path:

export PATH=$PATH:~/Dev/rock/bin/

Ubuntu has dev packages for sdl & friends:

sudo apt-get install libsdl1.2-dev libsdl-image1.2-dev libsdl-ttf2.0dev

For Arch and Gentoo, simply installing sdl & image/ttf will get you the headers as well, since they're non-noob distros.

Then this should run flawlessly:

rock -v window.ooc

If you run into pkg-config problems or another issue please file a bug against ooc-sdl

OSX 10.7

Make sure you have the latest XCode with Command line tools installed (for XCode 4.3+ you can install them in XCode's download preferences)

There's a homebrew formula for rock 0.9.3:

brew install rock

And for all the SDL libs we need as well:

brew install sdl sdl-image sdl-ttf

You need to add +-Wl,-framework,Cocoa to the rock command line. Otherwise it'll be missing some symbols. Also, libcaching seems to fail on OSX, so disable it:

rock --nolibcache +-Wl,-framework,Cocoa -v window.ooc

Note: + passes options directly from the ooc compiler to gcc. -Wl,arg1,arg2,arg3 seems to be a way to pass arguments from gcc to the linker directly. You can also use +-framework +Cocoa instead but it's just as ugly for no added benefit imho.

Note that the .pc file for SDL contains the '+-Wl,-framework,Cocoaline, as proves the output ofpkg-config sdl --libs`. But apparently rock ignores those because it doesn't recognize them. (It filters -I/-L/-l/*.a I think, that's a bug.)

You can package the resulting executable into an app with a bit of trickery, see this StackOverflow answer. Instead of doing the steps manually, use macdylibbundler

It'd be nice to have a utility that turns an .ooc app into a Mac app effortlessly - there's really not much to it. A few flags to add... depending on the size of your application you may have to add the compiler flag -headerpad_max_install_names so it leaves room for what install_name_tool has to do. Here's an example output of install_name_tool when it fails: https://trac.macports.org/ticket/26490

Win32

rock 0.9.4 is currently broken on Win32. That issue contains the workarounds needed to get 0.9.3 to compile though. Then, get it into your path. Here's what I did:

export PATH=$PATH:/g/Dev/rock-0.9.3-source/bin/

SDL provides a mingw distribution for the core SDL stuff, download and extract it to /c/. You should have a /c/SDL-1.2.15 directory now.

For SDL_image (and probably others) here's what I did:

  • Download the MSVC -devel version, extract it to /c/. You should have a /c/SDL_image-1.2.12 directory now.
  • Create the directory /c/SDL_image-1.2.12/include/SDL
  • Move /c/SDL_image-1.2.12/include/SDL_image.h to /c/SDL_image-1.2.12/include/SDL/SDL_image.h
  • Edit /c/SDL_image-1.2.12/include/SDL/SDL_image.h, prefix all the SDL includes with SDL/ (ie. SDL, SDL_version, begincode, closecode)

Then here's the final command line I used to compile it:

rock -nolibcache -v window.ooc +-Ic:\\SDL-1.2.15\\include +-Lc:\\SDL-1.2.15\\lib +-Ic:\\SDL_image-1.2.12\\include +-Lc:\\SDL_image-1.2.12\\lib\\x64 -lmingw32 -lSDLmain -lSDL

A few notes:

  • The order of -lmingw32, -lSDLmain, -lSDL matters, don't change it.
  • There doesn't seem to be a correct .pc file for SDL and/or SDL_image which is why we have to add the -I and -L ourselves.
  • You'll be tempted to use +-L/c/SDL-1.2.15/lib syntax - don't. Since they're not individual path components, they won't be recognized by mingw as such and won't be expanded to their proper windows form, which is why we have to do it manually.
  • For some reason, rock fails if you try to add the -I and -L directly, which is why we use the + syntax to pass it directly with gcc.
  • SDL on mingw will output stdout to stdout.txt and stderr to stderr.txt by default. See how to fix it here

I will probably write a script to do all that in the future or just release a complete SDL mingw-friendly dev kit on a git repo somewhere, for future use.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment