如何建立和放大器;安装GLFW 3和一个Linux项目中使用它 [英] How to build & install GLFW 3 and use it in a Linux project
问题描述
昨天晚上我工作到很晚试图从源头建立GLFW 3包的Linux版本。这个过程花了我很长的时间,共约3个小时,部分原因是因为我不熟悉CMake的,部分是因为我不太熟悉GLFW。
Last night I was working late trying to build the GLFW 3 packages for Linux from source. This process took me a very long time, about 3 hours in total, partly because I am unfamiliar with CMake, and partly because I am was unfamiliar with GLFW.
我希望这篇文章能够将你从我昨天的难度!我想我应该做一个简短的写了起来,并希望为您节省几个小时你的生活......
I hope that this post will save you from the difficulty I had yesterday! I thought I should make a short write-up, and hopefully save you several hours of your life...
由于urraka,B6,并在#glfw IRC频道尼古拉斯,我已经能够得到GLFW 3.0.1版的工作。
Thanks to "urraka", "b6" and "niklas" on the #glfw IRC channel, I have been able to get glfw version 3.0.1 working.
原来,这不是一个简单的过程(当然不是我,我不是专家),因为没有太多的文档中关于glfw3在网络上,特别是有关与CMake的设置它。
It turns out this is not a trivial process (certainly not for me, I am no expert) as there is not much documentation on the web about glfw3, particularly about setting it up with CMake.
有人问我这个分成的问题和答案部分,所以我这样做,得到的回答部分是现在的下面。
I was asked to split this into a question and answer section, and so I have done that, and the answer parts are now below.
如果任何GLFW3的维护者的看到这一点,那么我的消息对他们来说是请部分增加了建立GLFW3在Windows,Mac OS X和Linux到您的网站!这是很容易编写与GLFW方案,因为在线文档是相当不错的,所有可用类和模块的快速扫描,你会准备去。测试项目的例子在这里特色 也很不错。我发现两个主要问题是,首先我该如何设置GLFW3我的系统上,其次如何我建一个GLFW3项目?这两件事情也许还不太清楚足以让一个非专家。
If any of the maintainers of GLFW3 see this, then my message to them is please add a "setting up GLFW3 on Windows, Mac OS X and Linux" section to your website! It is quite easy to write programs with GLFW, since the online documentation is quite good, a quick scan of all the available classes and modules and you'll be ready to go. The example of a test project featured here is also very good. The two main problems I found were, firstly how do I set up GLFW3 on my system, and secondly how to I build a GLFW3 project? These two things perhaps aren't quite clear enough for a non-expert.
有一个简单的介绍一下今天(日期:2014年1月14日),它看起来好像GLFW网站经历了沉重的变化,因为我上次看,现在有上编译与GLFW GLFW和栋计划,我认为一节是新的。
Had a brief look today (Date: 2014-01-14) it looks as if the GLFW website has undergone heavy changes since I last looked and there is now a section on compiling GLFW and buliding programs with GLFW, which I think are new.
推荐答案
有关此安装,我使用的Kubuntu 13.04,64位。
Step 1: Installing GLFW 3 on your system with CMAKE
For this install, I was using KUbuntu 13.04, 64bit.
的第一个步骤是从www.glfw.org下载最新版本(假设在以后的工作版本以类似的方式),可能使用这链接。
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.
下一步是提取存档,打开一个终端。 CD
进入GLFW-3.XX目录并运行的CMake -G的Unix的Makefile
您可能需要提升权限,你可能还需要为首先安装编译依赖。要做到这一点,尝试 sudo易于得到建立-DEP GLFW
或 sudo易于得到建立-DEP glfw3
或 做手工的,因为我没有使用 sudo易于得到安装CMake的xorg-dev的的libglu1台面-dev的
... ...有可能是你需要其他库,如pthread的图书馆......显然,我有他们了。 (见给予G ++链接器阶段-l选项,下文。)
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. (See the -l options given to the g++ linker stage, below.)
现在,你可以键入制作
然后制作安装
,这可能会要求您须藤
第一。
Now you can type make
and then make install
, which will probably require you to sudo
first.
好吧,你应该得到的最后三个阶段的CMake一些冗长的输出,告诉你什么已建或在已放置。 (在 / usr / include目录
,例如。)
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.)
下一步是火了VIM(什么?!?!VIM你说的)或preferred IDE /文本编辑器...我没有使用vim,我用凯特,因为我在Kubuntu的13.04 ...无论如何,下载或从这里 复制的测试程序(在的底部页)和保存,退出。
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.
现在编译使用 G ++ -std = C ++ 11 -c的main.cpp
- 不知道C ++ 11的要求,但我用 nullptr
所以,我需要它。你可能需要将GCC升级到4.7版本,或即将推出的4.8版...阅读上的here.
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.
然后修正错误,如果你手工输入的程序或试图太聪明的东西没有工作......用这个怪物然后连接! G ++ main.o中-o main.exec -lGL -lGLU -lglfw3 -lX11 -lXxf86vm -lXrandr -lpthread -lXi
所以你看,在安装编译依赖的一部分,你可能还需要检查是否具有GL,GLU,X11 Xxf86vm(无论是)Xrandr POSIX线程和熙(无论是)发展还安装库。也许是太更新您的显卡驱动程序,我想GLFW 3可能需要OpenGL的3或更高版本?也许有人可以证实?您可能还需要添加连接选项 -ldl -lXinerama -lXcursor
来得到,如果你正在为 dlclose 未定义的引用使其正常工作code>(信贷@ user2255242)。
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
So you see, in the "install build dependencies" part, you may also want to check you have the GL, GLU, X11 Xxf86vm (whatever that is) Xrandr posix-thread and Xi (whatever that is) development libraries installed also. Maybe update your graphics drivers too, I think GLFW 3 may require OpenGL version 3 or higher? Perhaps someone can confirm that? You may also need to add the linker options -ldl -lXinerama -lXcursor
to get it to work correctly if you are getting undefined references to dlclose
(credit to @user2255242).
和,是的,我真的需要很多 -l </ code>取值!
And, yes, I really did need that many -l
s!
希望这些信息是正确的,一切为你工作,你喜欢写的GLFW测试程序。也希望本指南帮助,或会有所帮助,有几个人在未来谁是挣扎,因为我是今天昨天!
Hopefully this information was correct and everything worked for you, and you enjoyed writing the GLFW test program. Also hopefully this guide has helped, or will help, a few people in the future who were struggling as I was today yesterday!
顺便说一句,所有的标签都是我搜索计算器上寻找根本不存在的答案的事情。 (到现在为止)。我希望他们是你搜索的内容,如果你是在一个相似的位置自己。
By the way, all the tags are the things I searched for on stackoverflow looking for an answer that didn't exist. (Until now.) Hopefully they are what you searched for if you were in a similar position to myself.
这篇关于如何建立和放大器;安装GLFW 3和一个Linux项目中使用它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!