|
|
Installing Boost (required for using Gosu with C++ only)
Boost is a collection of libraries that is used throughout Gosu. Many parts of Boost have been marked for inclusion in the next standard of C++, so it's really worth a look!
Download and extract the latest Boost release. Open Terminal, 'cd' into to that directory and run:
./configure
make
sudo make install
sudo ln -s /usr/local/include/boost-1_34/boost /usr/include/boost(Replace "1_34" with boost's current version.)
If you are using MacPorts, you can, in theory, simply run sudo port install boost. In practice however, MacPorts' version of Boost is usually broken.
Starting a new Gosu game (C++)
In Xcode, create a new 'Application/Cocoa Application' project. Remove Resources/MainMenu.nib and main.m (files & references), right-click the project and add a reference to Gosu.framework (wherever you have unpacked it to).
In order to make the Boost headers accessible, select 'Project/Edit Active Project', search for 'Header Search Paths' in 'Build' and set it to /usr/local/include, or /opt/local/include if you used MacPorts to install Boost.
Your application also needs to include the Gosu.framework bundle. To instruct Xcode to automatically copy it into your application, choose Project/New Build Phase and select "Frameworks" as the Copy Files' target directory. Then locate this new build phase in the targets list and add Gosu.framework to it as well. (Note: You may have to drag & drop the framework into the build phase from the finder, instead of adding it via a right-click.)
You can then add new code files, for example the ones from the tutorial or this minimal application code:
#include <Gosu/Gosu.hpp>
class MyWindow : public Gosu::Window
{
public:
MyWindow()
: Gosu::Window(640, 480, false)
{
setCaption(L"Hello World!");
}
};
int main(int argc, char* argv[])
{
MyWindow win;
win.show();
}
Note: Usually, you want to right-click your target, Get Info, select Build/All Configurations/Build Locations and change the Per-configuration Build Products Path to '.' or something similar, so the application will have the correct position relative to your game's resources.
Starting a new Gosu game (Ruby)
Getting started with Ruby is a lot easier (surprise):
- If you installed Gosu using RubyGems (sudo gem install gosu), you just need to require 'rubygems' before you require 'gosu'.
- Otherwise you need to run your code in a way that require 'gosu' will work, i.e. by either copying gosu.bundle into the same directory or installing it in one of Ruby's default library paths.
To test if everything works, you can use this Hello World script:
require 'rubygems' # Remove if you aren't using RubyGems
require 'gosu'
class MyWindow < Gosu::Window
def initialize
super(640, 480, false, 20)
self.caption = 'Hello World!'
end
end
w = MyWindow.new
w.showThat's it — have fun!
Sign in to add a comment

Is it possible to create a C++ game without X-Code?
Sure, it's just a pain to create proper .app bundles without Xcode :) I think it's easiest if you compile a game as shown above to create the .app skeleton (with Gosu.framework included etc.), then switch to compiling just the binary core, which should be as easy as gcc mygame.cpp -F Path/To/Gosu --framework Gosu -o MyGame.app/Contents/MacOS/MyGame.
Hi Julian. I'm confused regarding the Ruby installation for OS X.
The above command yields Gosu version 0.7.7.1. The project's home page, however, lists 0.7.8.5 as the latest version.
Downloading the tar from the home page gives me a directory structure different from that of the gem install.
Working with the gem version is easy: require 'gosu' and go.
The tar, however, isn't as clear.
If I download and unzip the tar, how can I hook into it through Ruby?
Argh. Nevermind.
...by copying gosu.bundle into the same directory or installing it in one of Ruby's default library paths.
The gem install is the preferred way though, and it's strange that Gem installs the very outdated 0.7.7.1 version. What's the output of gem --version? It may be necessary to update to the latest RubyGems? version; they have changed something about the OS detection in 0.9.4 or so.
I used the newest version of RubyGems? and got
tqp15:~ yann$ gem install gosu Bulk updating Gem source index for: http://gems.rubyforge.org Successfully installed gosu-0.7.7.1-universal-darwin-9 1 gem installed
"require 'gosu'" does not work however... ? Do I still need to copy gosu.bundle?
First, what version of RubyGems? are you on? It's very weird that both of you got 0.7.7.1 even offered by gem :( Second, because RubyGems? isn't yet built into Ruby, you first need to require 'rubygems' before you can require 'gosu'. That should do the trick.
tqp15:gosu yann$ gem --version 1.0.1
require 'rubygems' does the trick. Thanks
Hi all.
I´m new with Gosu and I´ve got a problem testing Gosu examples. For example, When i try in console 'ruby ChipmunkIntegration?.rb' this error appears:
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require': no such file to load -- chipmunk (LoadError?)
Other cuestion, do i need something else for running OpenGL Gosu examples?. When i try 'ruby OpenGLIntegration.rb' this error appears too:
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require': no such file to load -- gl (LoadError?)
I use Gosu in Mac OS X Leopard.
Thank you all!!.
gules01: Both examples show how to integrate Gosu with other libraries who have to be installed separately, the same would apply to RMagickIntegration.rb. To compile Chipmunk, download it at http://files.slembcke.net/chipmunk/release/ChipmunkLatest.tgz and then follow the building instructions (I think it's ruby extconf.rb, make), then copy the resulting chipmunk.bundle file into Gosu's examples directory. OpenGL for Ruby should be easier: Install it via sudo gem install ruby-opengl. If that does NOT work, you will need to update rubygems first (sudo gem update --system).
Hope this helps :)
Hi Julian.
Thank you replying me :).
I updated rubygems, I have made:
sudo gem update --system sudo gem install rails
Now I´ve got 1.1.1 RubyGems? version, but I´ve noticed some strange things:
when I try 'sudo gem update' appears:
Updating installed gems Updating fastthread Building native extensions. This could take a while... ERROR: While executing gem ... (Gem::Installer::ExtensionBuildError?)
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby extconf.rb update creating Makefile
make gcc -I. -I/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/universal-darwin9.0 -I/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/universal-darwin9.0 -I. -fno-common -arch ppc -arch i386 -Os -pipe -fno-common -c fastthread.c cc1: error: unrecognized command line option "-arch" cc1: error: unrecognized command line option "-arch" make: [fastthread.o] Error 1
Gem files will remain installed in /Library/Ruby/Gems/1.8/gems/fastthread-1.0.1 for inspection. Results logged to /Library/Ruby/Gems/1.8/gems/fastthread-1.0.1/ext/fastthread/gem_make.out
And a similar error appers when i try 'sudo gem install ruby-opengl':
Building native extensions. This could take a while... ERROR: Error installing ruby-opengl:
rake RUBYARCHDIR=/Library/Ruby/Gems/1.8/gems/ruby-opengl-0.60.0/lib RUBYLIBDIR=/Library/Ruby/Gems/1.8/gems/ruby-opengl-0.60.0/lib /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby mkrf_conf.rb (in /Library/Ruby/Gems/1.8/gems/ruby-opengl-0.60.0) rake gcc -fno-common -arch ppc -arch i386 -Os -pipe -fno-common -DRUBY_VERSION=186 -I/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/include -I/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/universal-darwin9.0 -I/Library/Ruby/Site/1.8 -I. -c gl-1.0-1.1.c (in /Library/Ruby/Gems/1.8/gems/ruby-opengl-0.60.0/ext/gl) cc1: error: unrecognized command line option "-arch" cc1: error: unrecognized command line option "-arch" rake aborted! Command failed with status (1): -fno-common -arch ppc -arch i386 -Os ...? /Library/Ruby/Gems/1.8/gems/ruby-opengl-0.60.0/ext/gl/rakefile:29 (See full trace by running task with --trace) rake aborted! Command failed with status (1): [rake...]
(See full trace by running task with --trace)
Gem files will remain installed in /Library/Ruby/Gems/1.8/gems/ruby-opengl-0.60.0 for inspection. Results logged to /Library/Ruby/Gems/1.8/gems/ruby-opengl-0.60.0/gem_make.out
Can you help me??
Thank you again!!.
Bye.
Sounds you have a weird version of gcc installed; what does 'gcc --version' print? It should be the one from the Xcode development tools.
Hi!!.
Typing 'gcc --version' It prints:
gcc (GCC) 4.4.0 20080314 (experimental) revision 133226? Copyright (C) 2008 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
I installed the X-Code package from the Leopard CD.
Thank you for your help!!.
You must somehow have installed a very odd gcc version after Xcode has installed its own (4.0.something); or at least it hides the Apple one in your PATH. Is this '/usr/bin/gcc'? If so, I would try installing the Xcode tools over it again.
Hi.
Yes, gcc is in /usr/bin/gcc. I´ll try installing Xcode again.
Thank you.
Hi.
I have deleted the ruby Mac OS, reinstalled Xcode and I have installed ruby using macports. Later I have installed gosu using 'sudo gem install gosu' but when i try examples that works fine before i get an error, for example in 'ruby CptnRuby?.rb' i get:
/opt/local/lib/ruby/gems/1.8/gems/gosu-0.7.9.1-universal-darwin-9/lib/gosu.bundle: dlopen(/opt/local/lib/ruby/gems/1.8/gems/gosu-0.7.9.1-universal-darwin-9/lib/gosu.bundle, 9): Library not loaded: /usr/lib/libruby.1.dylib (LoadError?)
I dont know if is usefull but i print gem --env command:
RubyGems? Environment:
Thank you. Bye.
Well Ruby was fine, it was just gcc that was a problem! It seems Gosu always tries to load libruby from /usr/lib — so one workaround would be to create a symlink there: sudo ln -s /opt/local/lib/ruby/libruby.1.dylib /usr/lib/libruby.1.dylib (look up the filename for MacPorts??' libruby dylib file just to be safe, I'm just guessing where it could be! :))
I think at a later point Gosu should be able to use MacPorts?' Ruby completely, but since it's the same version of Ruby that ships with Leopard at the moment, I don't think this is critical for now. Feel free to open a feature request ticket in the Issue Tracker anyway :)
Hi!!.
At least, with your last advise about make a simbolic link I have remembered I deleted all Mac ruby libs and I have had libruby.1.dylib as a simbolic link to a that deleted Mac ruby lib. I have copied libruby.1.8.6.dylib as libruby.1.dylib from /opt/local/lib to /usr/lib and now all is working fine, include all OpenGL examples (with the macports ruby installation OpenGL now is ok too, with my gcc problems i cant before).
For helping me, thank you very much.
See you soon :). Bye.
I've been trying to install both gosu and boost for the past few days however I am encountering some problems. I have been trying to install boost, as per the above short guide, and am unsure if I have installed correctly since I have tried compiling a short example from boost.org (namely one that makes use of the lambda library) and am getting complaints despite using the -I /path and -L /path parameters. Is there an easier way than compiling boost from scratch like this? Would using macports be easier? It's mentioned that (for 1.34) boost is broken when using macports, is this still the case?
Also, is Boost totally necessary to run a Gosu ruby script or C++ app? At one point I used a short example from this site to test if Gosu ran and it did. Later on I got errors when trying to run the same script, ruby was complaining about the gosu library. Is this a result of boost not being installed correctly?
Dean, you only need boost if you want to use Gosu from C++, and yes, it is totally necessary for that :) It has no influence whatsoever on the Ruby version though. You just have to make sure that either the gosu.bundle file can be reached from the Ruby game that requires it, or that you install Gosu using RubyGems? and 'require rubygems' before requiring 'gosu'.
You can try out MacPorts?. I wrote that it's usually broken because it's only worked for me once, but of course when it works it's the easiest solution. Actually, for Gosu it is enough if the headers are available, i.e. you should be fine if you just copy the 'boost' folder from the Boost archive (the one that includes all the headers) into the /usr/include directory.
Julian, I'm not sure where the proper place for this is, but I just want to say THANK YOU for such a great framework. I just deployed my (ruby) game for the first time today on both OS X and Windows and all went quite smoothly. Ruby as always is a pleasure to code in and I'm thankful for the intuitive interface. Kudos!
>> unrecognized command line option "-arch" cc1: error: unrecognized command line option "-arch" make <<
For anyone getting the '-arch' Option Not Recognized error when 'gem install' runs the 'make gcc' command, here's a tip. (I was installing ruby-debug-base, but probably a similar problem)
In my case, I had MacPorts? installed, and GNU gcc 4.2 was in /opt/local/bin/gcc. That path was before the /usr/bin path in $PATH. You just have to run 'sudo port deactivate gcc42' and it will fix itself. See below...
macbook:~ garyrp$ which gcc /opt/local/bin/gcc <-----GNU gcc 4.2, doesn't know about Apple's -arch flag
macbook:~ garyrp$ sudo port deactivate gcc42 ---> Deactivating gcc42
macbook:~ garyrp$ which gcc /usr/bin/gcc <-------- gcc 4.0, Apple/BSD, knows about -arch flag
macbook:~ garyrp$ sudo gem install WHATEVER
One gotcha to be aware of: This changes the default gcc for new processes, but your current term window will still think it is /opt/local/bin/gcc... You need to open a new term window to get the refreshed env...
Hi, I'm not sure this is related to Gosu. Even with all weird sorts of MacPorts? compilers installed, 'gem install gosu' shouldn't ever compile anything? :)