如何在Linux上构建GLFW3项目? [英] How to build GLFW3 project on Linux?

查看:150
本文介绍了如何在Linux上构建GLFW3项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用cmake和make编译了glfw3和随附的示例,而没有出现问题。开始编写我的第一个项目。我是opengl和glfw的新手,并且没有C和CMake的经验,所以我很难理解示例构建文件,甚至是要在我的项目中使用的链接和/或编译器参数的库。

I've compiled glfw3 and the included examples using cmake and make without problems. Onto writing my first project. Being new to opengl and glfw, and unexperienced with C and CMake, i'm struggling to understand the example build files, or even which libraries to link and/or compiler parameters to use in my project.

比方说,我现在只有一个文件夹和一个文件, boing.c 。我将如何编译它?

Let's say i have just one folder with one file, boing.c for now. How would i compile it?

只需运行 gcc -lglfw3 -lm -lGL -lGLU boing.c 未定义引用的墙,以sin和atan2开头,然后是各种gl和glfw内容。我缺少什么?

Simply running gcc -lglfw3 -lm -lGL -lGLU boing.c gives a wall of undefined references, starting with sin and atan2, followed by various gl and glfw stuff. What am i missing?

我将如何编写makefile?是否有我不知道如何使用或适应的cmake模板或示例?有谁知道使用glfw3的开源项目(或者更好的是一个小例子或模板),这样我就可以看看吗?

How would i go about writing a makefile? Is there a cmake template or sample, that i just didn't understand how to use or adapt? Does anyone know about an open source project (or better, a small example or template) using glfw3 -- so i can look around?

我猜cmake将会是最好,当我想在某个时候使用多平台时。但是我如何才能轻松地编译****东西,让我可以开始一些教程呢??

I'm guessing cmake would be best, when i want to go multi-platform at some point. But how do i just get the **** thing to compile without too much hassle, so i can get started on some tutorials..?

我是中等新手使用32位Ubuntu raring。

I'm a moderate noob using 32bit Ubuntu raring. Just using Vim for now.

推荐答案

我强烈建议您安装CMake(如果尚未安装)。

I would strongly suggest installing CMake if you haven't already.

尽管我建议使用CMake,但可以理解,它不是最简单的工具,但比制作自己的make文件要好得多。

Even though I suggest using CMake, it is understandably not the easiest tool to use, but is much better than making your own make files.

编译 boing.c (顺便说一句,是glwf为那些不知道的人提供的示例)
在glfw根目录中并键入 cmake。然后 make

To compile boing.c (which btw, is an example provided by glwf for those who are unaware) Be in the glfw root directory and type cmake . then make

这应该构建所有

但是,为了回答如何制作简单的CMake文件,下面是一个示例CMakeLists.txt,用于构建 boing.c

But, to answer how to make a simple CMake file, here is an example CMakeLists.txt to build boing.c:

cmake_minimum_required(VERSION 2.8)

project( BOING_PROJECT ) # this is case sensitive 

######################################
# finds OpenGL, GLU and X11
find_package(OpenGL REQUIRED)
if(NOT OPENGL_FOUND)
    message("ERROR: OpenGL not found")
endif(NOT OPENGL_FOUND)
set(GL_LIBRARY GL GLU X11)

add_executable(boing boing.c)

# linking "glfw" and not "glfw3" 
# assumes that glfw was built with BUILD_SHARED_LIBS to ON
target_link_libraries(boing glfw ${GL_LIBRARY} m)

上面的目录结构为

boing_project/  
    boing.c  
    CMakeLists.txt  

但是,这并不能回答为什么您得到全部这些错误。

However, that does not answer why your getting all those errors.

错误的原因是,您以错误的顺序向GCC提供了参数,请尝试

gcc boing。 c -lglfw3 -lm -lGL -lGLU

或更高

gcc boing.c -o boing -Wall -lglfw3- lm -lGL -lGLU

The cause of your errors is that you supplied the arguments to GCC in the wrong order, try
gcc boing.c -lglfw3 -lm -lGL -lGLU
or better
gcc boing.c -o boing -Wall -lglfw3 -lm -lGL -lGLU

要回答您的问题:是否有使用 glfw 您可以浏览?只需在github上搜索 glfw ,您就会发现很多。

To answer your question: are there any open source projects that use glfw that you can look through? Just search for glfw on github and you'll find plenty.

这篇关于如何在Linux上构建GLFW3项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆