LearnOpenGL.com: Setup Gotchas on Ubuntu 16.04 and Code::Blocks

I began working through the fantastic OpenGL tutorials on learnopengl.com today and hit a couple of issues along the way.

Most of the issues I hit were caused by the fact that the tutorials are heavily biased towards Windows and Visual Studio while I’m using Ubuntu 16.04 and Code::Blocks.

Dependencies

The first issue I needed to resolve was the installation of the dependencies for GLFW. These can be installed using the following command:

sudo apt-get update && \
sudo apt-get -y install \
build-essential \
libx11-dev \
libxrandr-dev \
libxinerama-dev \
libxcursor-dev \
libgl1-mesa-dev

Linker

The next issue I faced was linking the GLFW library with my project in Code::Blocks.

After compiling the GLFW library from source (as per the tutorial) I decided to install GLFW from the Ubuntu repos (just to be sure I had a version that was compiled correctly).

sudo apt-get install libglfw3-dev

The tutorial recommended the following compiler flags to let the linker know where the required libraries are located:

-lGLEW -lglfw3 -lGL -lX11 -lpthread -lXrandr -lXi

But these flags gave me the following error:

cannot find -lglfw3

After a quick find I found that the issue was the library name. It was not called libglfw3 but was instead called libglfw:

$ find / -name *glfw* 2>/dev/null
...
/usr/lib/x86_64-linux-gnu/libglfw.so
...

To fix the issue you need to use -lglfw in place of -lglfw3.

NOTE: To set compiler linker flags in Code::Blocks you need to go to Settings > Compiler > Global Compiler Settings > Linker Settings > Other Linker Options

nullptr

I also had an issue with the nullptrs used in the example code even though my version of g++ is 5.4.0. I was getting the following error:

error: 'nullptr' was not declared in this scope

To fix this I had to add the following compiler flag:

-std=gnu++0x

NOTE: To set compiler flags in Code::Blocks you need to go to Settings > Compiler > Global Compiler Settings > Compiler Settings > Other Compiler Options

std::cout

The final issue I had was with std::cout and std::endl. I was getting the following errors:

error: 'cout' is not a member of 'std'
error: 'endl' is not a member of 'std'

In order to fix this I needed to include iostream.

#include <iostream>
comments powered by Disqus