Create opengl glfw3 project in Code::Blocks


In this tutorial, I will explain the process needed to create a project in Code::Blocks (1.1), using glfw3 (2.5) and mingw (tdm64-gcc-


Download respective versions (or newer) of these software. Instal Code::Blocks first and then install mingw to C:\ drive as root. After installation “C:\MinGW\mingw64” should be your root direction (aka there should be the bin folder). Add the bin directory to your windows path variable (not required for our purpose though). Unzip glfw3 archive to some directory (lets assume Documents\apps\glfw-3.1.1-64).


1. After installation of all of above packages, open Code::Blocks and go to Settings->Compiler->Global compiler settings->Toolchain executables. In the Toolchain executables directory set “Compiler’s installation directory” to “C:\MinGW\mingw64“. Fill all the respective textboxes under Program Files tab to “gcc.exe, g++.exe, g++.exe, ar.exe, GDB/CDB debugger : Default, windres.exe and ming32-make.exe” respectively.¬† In the Compiler settings tab go to Compiler Flags and check “Have g++ follow the C++11 ISO C++ language standard [-std=c++11]“. The Selected compiler¬† drop down should show (at the top) should show “GNU GCC Compiler“. Click “OK” to close the window.

2. Restart Code::Blocks (close and open) and create a new Project (console application). In the language selection window, select c++, give a project title and location in the next window. In the next window make sure “GNU GCC Compiler” is selected (click Finish). Right click the project name in the default workspace and go to build options. In the Project build options window select project name on the left and go to “Linker settings” tab. Press Add button under Link libraries pane. Browse to glfw3 installation directory, select both glfw3dll.a and libglfw3.a inside lib-mingw directory and press Open button. When the popup box says “Keep this as relative path?” select “No“. Press OK on the Add library dialog box. Press “OK” on the Project build options window.


Replace the code in main.cpp with following code

#include <GLFW/glfw3.h>
#include <thread>

int main()

Save the file and press the Build icon. After building the project, if you try to run it won’t run, because we haven’t still attached glfw3.dll to our project. Copy glfw3.dll from lib-mingw directory we selected above and copy it to your project’s bin/Debug directory. You need to browse to the exact location where your project is created. Now, if you try to run the project it should run without any problems.



Tags: , , , , ,

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s