How to build & install GLFW 3 and use it in a Linux project

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 -ls!

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.)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值