The OpenGL has been originally provided on macOS. However, to ease our
development, we need to install
GLFW using Homebrew, by
brew install glew glfw.
GLEW website states: “GLEW provides efficient run-time
mechanisms for determining which OpenGL extensions are supported on the
target platform”. It’s a useful extension for developing OpenGL
GLFW is an extension for managing windows. OpenGL is a
bare-bones library which does not concern itself with the creation and
management of windows. That job is made easy by GLFW.
Including and Linking on macOS
⚠️ Warning: On macOS you're not using libraries to include system level APIs, but Frameworks.
To include headers in source, use
#include <OpenGL/gl.h> and
To link OpenGL libraries, use options
-framework OpenGL and
Make sure to use something like
#ifdef __APPLE__ when determining how
#include the headers, the rest of the world tends to follow the
The minimal compilation can be done by
g++is the compiler. No surprises here.
main.cppis the file which contains the code (e.g. the above code) and is to be compiled
-otest.o specifies that the output executable should be named
-lGLEWlinks the libraries GLFW and GLEW (which we installed via
-framework OpenGLis the important flag which links the actual OpenGL framework to our code.
Note that, since our
brew install path
/usr/local/ is not in search
paths by default, to make it available at system level, we can add
search paths in
A Simple Makefile Sample
Here we provides a simple example of
makefile, supposing we have