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.
我已经使用cmake和make编译了glfw3和包含的示例,并且没有问题。写我的第一个项目。作为opengl和glfw的新手,我对C和cmake没有经验,我很难理解示例构建文件,甚至很难理解在我的项目中要链接和/或编译器参数的库。
Let's say i have just one folder with one file, boing.c
for now. How would i compile it?
假设我只有一个文件夹有一个文件,boing。现在c。如何编译它?
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?
简单地运行gcc -lglfw3 -lm -lGL -lGLU boing。c给出了一堆未定义的引用,从sin和atan2开始,然后是各种gl和glfw。我缺少什么?
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?
我将如何编写makefile?是否有一个cmake模板或样本,我只是不知道如何使用或适应?有人知道使用glfw3的开源项目(或者更好的例子或模板)吗?
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..?
我猜cmake会是最好的,当我想在某个时候使用多平台的时候。但是我如何让**的东西编译而不太麻烦,这样我就可以开始学习一些教程了。
I'm a moderate noob using 32bit Ubuntu raring. Just using Vim for now.
我是一个使用32位Ubuntu软件的新手。现在就用Vim。
3 个解决方案
#1
9
I would strongly suggest installing CMake if you haven't already.
如果您还没有安装CMake,我强烈建议您安装CMake。
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.
尽管我建议使用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
编译定票。c(顺便说一下,这是glwf为不知情的人提供的一个示例)位于glfw根目录中,并输入cmake。然后
And that should build all of the examples.
这应该是所有例子的基础。
But, to answer how to make a simple CMake file, here is an example CMakeLists.txt to build boing.c
:
但是,为了回答如何创建一个简单的CMake文件,这里有一个CMakeLists示例。三种构建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)
The directory structure of the above would be
上面的目录结构是
boing_project/
boing.c
CMakeLists.txt
However, that does not answer why your getting all those errors.
然而,这并不能解释为什么您会得到所有这些错误。
The cause of your errors is that you supplied the arguments to GCC in the wrong order, trygcc boing.c -lglfw3 -lm -lGL -lGLU
or bettergcc boing.c -o boing -Wall -lglfw3 -lm -lGL -lGLU
您错误的原因是您以错误的顺序将参数提供给GCC,请尝试GCC boing。c -lglfw3 -lm -lGL -lGLU或更好的gcc boing。c -o boing -Wall -lglfw3 -lm -lGL -lGLU
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.
要回答您的问题:有使用glfw的开源项目可以查看吗?只要在github上搜索glfw,你就会找到很多。
#2
12
You need to include library like this
您需要像这样包含库
-lGL -lGLU -lglfw3 -lX11 -lXxf86vm -lXrandr -lpthread -lXi
-lGL -lGLU -lglfw3 -lX11 -lXxf86vm -lXrandr -lpthread -lXi
#Ref : http://www.blogosfera.co.uk/2013/07/how-to-build-install-glfw-3-and-use-it-in-a-linux-project/
#裁判:http://www.blogosfera.co.uk/2013/07/how-to-build-install-glfw-3-and-use-it-in-a-linux-project/
Sorry i'm not good in english
对不起,我的英语不好
#3
0
I manage to build glfw projects using the following flags: Compiler flags:
我设法使用以下标志构建glfw项目:编译器标志:
-c -Wall
Linker flags:
链接器标记:
-lglfw3 -lGLEW -lX11 -lXrandr -lXinerama -lXi -lXxf86vm -lXcursor -ldl -lGL -lm -lpthread
#1
9
I would strongly suggest installing CMake if you haven't already.
如果您还没有安装CMake,我强烈建议您安装CMake。
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.
尽管我建议使用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
编译定票。c(顺便说一下,这是glwf为不知情的人提供的一个示例)位于glfw根目录中,并输入cmake。然后
And that should build all of the examples.
这应该是所有例子的基础。
But, to answer how to make a simple CMake file, here is an example CMakeLists.txt to build boing.c
:
但是,为了回答如何创建一个简单的CMake文件,这里有一个CMakeLists示例。三种构建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)
The directory structure of the above would be
上面的目录结构是
boing_project/
boing.c
CMakeLists.txt
However, that does not answer why your getting all those errors.
然而,这并不能解释为什么您会得到所有这些错误。
The cause of your errors is that you supplied the arguments to GCC in the wrong order, trygcc boing.c -lglfw3 -lm -lGL -lGLU
or bettergcc boing.c -o boing -Wall -lglfw3 -lm -lGL -lGLU
您错误的原因是您以错误的顺序将参数提供给GCC,请尝试GCC boing。c -lglfw3 -lm -lGL -lGLU或更好的gcc boing。c -o boing -Wall -lglfw3 -lm -lGL -lGLU
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.
要回答您的问题:有使用glfw的开源项目可以查看吗?只要在github上搜索glfw,你就会找到很多。
#2
12
You need to include library like this
您需要像这样包含库
-lGL -lGLU -lglfw3 -lX11 -lXxf86vm -lXrandr -lpthread -lXi
-lGL -lGLU -lglfw3 -lX11 -lXxf86vm -lXrandr -lpthread -lXi
#Ref : http://www.blogosfera.co.uk/2013/07/how-to-build-install-glfw-3-and-use-it-in-a-linux-project/
#裁判:http://www.blogosfera.co.uk/2013/07/how-to-build-install-glfw-3-and-use-it-in-a-linux-project/
Sorry i'm not good in english
对不起,我的英语不好
#3
0
I manage to build glfw projects using the following flags: Compiler flags:
我设法使用以下标志构建glfw项目:编译器标志:
-c -Wall
Linker flags:
链接器标记:
-lglfw3 -lGLEW -lX11 -lXrandr -lXinerama -lXi -lXxf86vm -lXcursor -ldl -lGL -lm -lpthread