Getting Started on OS X

Julian Raschke edited this page Dec 10, 2016 · 13 revisions

Getting Started on macOS


Gosu depends on the SDL 2 library. After installing Homebrew, you can simply run brew install sdl2.

If you have not installed a custom Ruby via rbenv yet, I recommend also running brew install ruby. The problem with Apple's built-in Ruby is that it is often outdated and/or broken. The popular rvm tool is not compatible with Gosu. Ruby from Homebrew and rbenv are both good choices.

Installing Ruby/Gosu

Simply install the Gosu gem via gem install gosu.

To test whether everything works as expected, you can use this one-liner, which should open a window:

ruby -rgosu -e 'w =, 150); w.caption = "It works!";'

Or you can install and run the gosu-examples gem:

gem install gosu-examples

Creating a New C++ Gosu Project

TODO: This does not yet explain how resource loading works: Add your resources to the Xcode project and use Gosu::resource_path to find them.

Gosu uses CocoaPods to streamline the Xcode project setup. Even though CocoaPods calls itself an "Objective C library manager", it is a great tool to integrate the C++ based Gosu library into your project along with all its dependencies.


  • Xcode from the Mac App Store
  • In Xcode, make sure to visit the preferences and install the Command Line Tools
  • CocoaPods, which can be installed using sudo gem install cocoapods (again, omit sudo if you are using rbenv)

Creating the project

Start Xcode and create a new project. Use the template 'OS X/Application/Cocoa Application':

None of the settings in the following dialog are required, so you can leave them all unchecked:

Remove & trash the following files:

  • Classes/AppDelegate.h
  • Classes/AppDelegate.m
  • Resources/MainMenu.xib

Now close the project, open your text editor of choice and create a file called Podfile in the same directory as your .xcodeproj:

platform :osx, '10.7'

pod 'Gosu', :git => ''

On the command line, navigate to the folder in which you created the Podfile and run pod install. This will create an .xcodeworkspace file that contains your project, Gosu and all of its dependencies.

Adding Code and Resources

At this point, your project still contains the main.m file that Xcode has generated for you. Rename it to main.cpp and replace its contents by the following code:

#include <Gosu/Gosu.hpp>

class MyWindow : public Gosu::Window
    :   Gosu::Window(640, 480)
        setCaption(L"Hello World!");

int main()
    MyWindow window;;

If you "Build & Run" the project now (cmd+R), you should see an empty, black window with the caption "Hello World".