GLFW3
This may not be the correct place for this “question”, indeed it is actually an answer, or I hope it will be for you! However, since I have worked for several hours this evening trying to install the latest version of the glfw libraries using cmake on my system, and found it to be the most difficult thing I have tried to install to date, I thought I should make a short write-up, and hopefully save you several hours of your life.
Thanks to “urraka”, “b6″ and “niklas” on the #glfw IRC channel, I have been able to get glfw version 3.0.1 working.
It turns out this is not a trivial process (certainly not for me, I am no expert) and took me approximately 3 hours. There is not much documentation on the web about glfw3, particularly about setting it up with cmake.
Installing on your System with CMAKE
The first step is to download the latest version (assuming versions in the future work in a similar way) from www.glfw.org, probably using this link.
The next step is to extract the archive, and open a terminal. cd
into the glfw-3.X.X directory and run cmake -G "Unix Makefiles"
you may need elevated privileges, and you may also need to install build dependencies first. To do this, try sudo apt-get build-dep glfw
or sudo apt-get build-dep glfw3
or do it manually, as I did using sudo apt-get install cmake xorg-dev libglu1-mesa-dev
… There may be other libs you require such as the pthread libraries… Apparently I had them already.
Now you can type make
and then make install
, which will probably require you to sudo
first.
Okay, you should get some verbose output on the last three cmake stages, telling you what has been built or where it has been placed. (In /usr/include
, for example.)
Create a test program and compile
The next step is to fire up vim (“what?! vim?!” you say) or your preferred IDE / text editor… I didn’t use vim, I used Kate, because I am on KUbuntu 13.04… Anyway, download or copy the test program from here (at the bottom of the page) and save, exit.
Now compile using g++ -std=c++11 -c main.cpp
– not sure if c++11 is required but I used nullptr
so, I needed it… You may need to upgrade your gcc to version 4.7, or the upcoming version 4.8… Info on that here.
Then fix your errors if you typed the program by hand or tried to be “too clever” and something didn’t work… Then link it using this monster! g++ main.o -o main.exec -lGL -lGLU -lglfw3 -lX11 -lXxf86vm -lXrandr -lpthread -lXi
And, yes, I really did need that many -l
s!
You are finished, have a nice day!
Hopefully this information was correct and everything worked for you, and you enjoyed writing a glfw program. Also hopefully this has helped, or will help, a few people in the future who were struggling as I was today!
By the way, all the tags are the things I searched for on stackoverflow looking for an answer that didn’t exist. (Until now.)