Getting Ruby/SDL to Work on Mac OS X
With 3 days invested into this project, I’m betting this little walk-through will be of benefit to others. I’ve wanted for quite some time to get a Simple DirectMedia Layer binding for Ruby working on my Mac—but it wasn’t as easy as it sounded. With this step behind me, however, I can begin the game programming I’ve always dreamed of! The world will soon be MINE. Ahem. Well, as long as we’re in it together, I might as well show you how to take over the world too.
The Journey
First of all, forget RUDL. Although it’s easy to install on Windows, I couldn’t find a way to build it for the Mac. So I turned to Ruby/SDL by Ohai.
While the base C++ SDL library appears to be very Mac-friendly (its default binary install is a Framework) the other pieces that sit on top of it have either little or zero support for Frameworks. So it’s best to build and install the Mac OS version of .so files—dylibs. Here’s how I got Ruby/SDL installed and running:
Note:The following instructions assume that you have XCode and the Mac OS X developer tools installed.
Ruby
wget ftp://ftp.ruby-lang.org/pub/ruby/ruby-1.8.3.tar.gz
tar -xzvf ruby-1.8.3.tar.gz
cd ruby-1.8.3
./configure
make
sudo make install
You will need to remove any darwin ports or Mac OS X native Ruby stuff (or at least make sure that the above Ruby install gets first precedence in your PATH and LD environment variables). I had problems on several occasions, especially on the very last step when trying to get rsdl to compile properly if I didn’t use a fresh install of Ruby compiled from source. The rsdl program is essential for any Ruby/SDL programs to run properly on Mac OS X. It acts like a wrapper to Cocoa so that Ruby programs can deal with drawing and windows in conjunction with the operating system.
SDL
wget http://www.libsdl.org/release/SDL-1.2.9.tar.gz
tar -xzvf SDL-1.2.9.tar.gz
cd SDL-1.2.9
./configure
make
sudo make install
SDL Image
sudo port install libpng
sudo port install jpeg
# (Darwin Ports installed libpng and libjpg in /opt/local/lib)
wget http://www.libsdl.org/projects/SDL_image/release/SDL_image-1.2.4.tar.gz
tar -xzvf SDL_image-1.2.4.tar.gz
cd SDL_image-1.2.4
export CFLAGS=\"-I/opt/local/include -L/opt/local/lib/\"
./configure
make
sudo make install
SDL TTF
wget http://www.libsdl.org/projects/SDL_ttf/release/SDL_ttf-2.0.7.tar.gz
tar -xzf SDL_ttf-2.0.7.tar.gz
cd SDL_ttf-2.0.7
./configure
make
sudo make install
SMPEG
#cvs -d:pserver:anonymous@cvs.icculus.org:/cvs/cvsroot login
#(password: \"anonymous\")
#cvs -z3 -d:pserver:anonymous@cvs.icculus.org:/cvs/cvsroot co smpeg
# Couldn't get SMPEG to link as a dylib
SDL Mixer
wget http://www.libsdl.org/projects/SDL_mixer/release/SDL_mixer-1.2.6.tar.gz
tar -xzf SDL_mixer-1.2.6.tar.gz
cd SDL_mixer-1.2.6
./configure
make
sudo make install
SGE
wget http://freshmeat.net/redir/sge/15814/url_tgz/sge030809.tar.gz
tar -xzvf sge030809.tar.gz
export USE_FT=\"n\"
make
# NOTE: New Makefile REQUIRED, see below
sudo make install # some errors having to do with .so files
sudo cp libSGE.dylib /usr/local/lib/
Get the new Makefile and Makefile.conf files from this email post. It looks like the list program munged the @executable_path in the Makefile, so be sure to change “at executable_path” to “@executable_path” without a space before it.
Ruby/SDL
wget http://www.kmc.gr.jp/~ohai/rubysdl/rubysdl-1.0.0.tar.gz
tar -xzvf rubysdl-1.0.0
cd rubysdl-1.0.0
ruby extconf.rb
make
sudo make install
RSDL
wget http://www.kumaryu.net/cgi-bin/diary/files/rsdl.tar.gz
tar -xzvf rsdl.tar.gz
cd rsdl
make
sudo cp rsdl /usr/local/bin
And there you go! Now, to run a Ruby/SDL program take note that you must use this new “rsdl” command-line tool to run it. In other words, instead of typing “ruby your_ruby_file.rb”, you will need to run it with “rsdl your_ruby_file.rb”. If anyone knows of a better alternative, please do let me know.
Final Notes
I couldn’t get smpeg working, although I think it’s possible with a little work. There are also some TTF library methods that appear to be disabled due to some missing libraries. I’m not sure what dependencies I’m missing, however.
Have fun!
November 19th, 2005 at 6:34 pm
I’m sure you posting this will save many people long hours of frustration. Thanks!
Hopefully, once you get an app up and running, you can try to package it with rubyscript2exe so your users won’t have to go through all the same pain.
November 19th, 2005 at 9:03 pm
Does rubyscript2exe have a Mac OS version? I thought it was Windows only…
January 5th, 2006 at 12:13 am
Thank you so much for this!
January 25th, 2006 at 8:56 am
Any chance you can post the Makefile and Makefile.conf for sge? The linked site keeps timing out on me.
Ralph
February 1st, 2006 at 10:19 pm
[…] Johnson under Ruby on Rails
Ralph Douglass has made some nice improvements to my earlier instructions for installing Ruby SDL on Mac OS X. In fact, his instructions are a mere 25 lines co […]
February 10th, 2006 at 1:30 pm
[…] uby SDL Running on Mac OS X Ralph Douglass has made some nice improvements to my earlier instructions for installing Ruby SDL on Mac OS X. In fact, his instructions are a mere 25 lines co […]
February 10th, 2006 at 2:54 pm
[…] ac OS X This is a must read Ralph Douglass has made some nice improvements to my earlier instructions for installing Ruby SDL on Mac OS X. In fact, his instructions are a mere 25 lines co […]
February 10th, 2006 at 3:30 pm
[…] Running on Mac OS X Really? Ralph Douglass has made some nice improvements to my earlier instructions for installing Ruby SDL on Mac OS X. In fact, his instructions are a mere 25 lines co […]