How to Use GLFW in XCode

First, download the GLFW source code.

Extract the tarball to a directory.

Open a terminal and cd to the extracted directory. Run cmake (if not already installed, install it!):

%>cmake .



%>make install

The header files will be placed under a GLFW directory in


and the library file in


To now use the libraries, start a new XCode project.

Screen Shot 2014-08-06 at 9.25.02 AM

Select “OS X Application” and “Command Line Tool.” Name the project whatever you like and save it somewhere.

Screen Shot 2014-08-06 at 9.25.18 AM

The first step is to link the search paths for the libraries and header files. With your project selected in the Project Navigator pane, select the “Build Settings” tab. In the search box, type Search Paths.

In header search paths, add


and select recursive.

Screen Shot 2014-08-06 at 9.26.26 AM

Similarly, under library search paths, add


and select recursive.

Screen Shot 2014-08-06 at 9.26.36 AM

Now, click the “Build Phases” tab. Under “Link Binary with Libraries,” we must add the appropriate libraries necessary for OpenGL and GLFW to function. First add the OpenGL framework. (You may type “OpenGL” in the search on the dialog box that comes up to quickly find it.)

Screen Shot 2014-08-06 at 9.31.40 AMWe must also add several libraries (frameworks) required by GLFW: Cocoa, OIKit, and CoreVideo. Add each of these in turn by finding them alphabetically or typing them in the search box.

Finally, add the GLFW library (libglfw3.a, located in the /usr/local/lib/ directory). In the framework add dialog box that pops up, click “Add Other.” Now this is a bit tricky, because the OS X file open dialog won’t allow you to select the /usr/ folder by default. The workaround is to download TinkerTool, and select “Show hidden and system files,” then click “Relaunch Finder.”

Screen Shot 2014-08-06 at 9.40.54 AM

Now, make the /usr/ folder a favorite as described in this post. The usr folder will now show up in the file open dialog for easily selecting the library.

Screen Shot 2014-08-06 at 9.44.33 AM

Your Build Phases pages should now look like this:

Screen Shot 2014-08-06 at 9.44.41 AM

Now, to test to see if it works, copy GLFW’s sample code from here into your main.cpp, then build and run.

Screen Shot 2014-08-06 at 9.51.50 AM



2 thoughts on “How to Use GLFW in XCode

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s