如何在NetBeans 8.1中进行设置以成功编译使用GLFW的OpenGL代码 [英] How to set up in NetBeans 8.1 to successfully compile an OpenGL code which uses GLFW

查看:96
本文介绍了如何在NetBeans 8.1中进行设置以成功编译使用GLFW的OpenGL代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Ubuntu 14.04 64位x86上使用NetBeans v8.1编译第9版"OpenGL编程指南"中的示例代码.该示例代码是triangles.cpp,这是本书的第一个示例代码,可从此处.我在项目属性"对话框的链接器"选项卡中添加了信息,如下所示: 您会看到其他图书馆目录",图书馆"和其他选项"字段充满了所需的正确信息(至少我认为是这样).

I am trying to compile a sample code in the 9th edition of "OpenGL Programming Guide" using NetBeans v8.1 on Ubuntu 14.04 64bit x86. The sample code is triangles.cpp, the first sample code of the book, downloadable from here. I have added information in the "Linker" tab of Project Properties dialog as follows: You can see that "Additional Library Directories", "Libraries" and "Additional Options" fields are filled with needed and correct information (at least I think so).

但是,当我通过单击IDE中的清理并生成项目"按钮来生成项目时,出现了很多错误:

However, when I build the project by clicking the "Clean and Build Project" button in the IDE, I got tons of errors:

g++    -c -g -I/home/me/ComputerGraphics/include -I/home/me/glfw-3.2.1/include -MMD -MP -MF "build/Debug/GNU-Linux/01-triangles.o.d" -o build/Debug/GNU-Linux/01-triangles.o 01-triangles.cpp
mkdir -p dist/Debug/GNU-Linux
g++     -o dist/Debug/GNU-Linux/opengl1 build/Debug/GNU-Linux/01-triangles.o -L/home/me/glfw-3.2.1/bin/lib -Wl,-rpath,/home/me/glfw-3.2.1/bin/lib -lglfw3 -pthread -ldl -lGLU -lGL -lrt -lXrandr -lXxf86vm -lXi -lXinerama -lX11
build/Debug/GNU-Linux/01-triangles.o: In function `init()':
/home/me/ComputerGraphics/OpenGL1/01-triangles.cpp:27: undefined reference to `gl3wGenVertexArrays'
/home/me/ComputerGraphics/OpenGL1/01-triangles.cpp:28: undefined reference to `gl3wBindVertexArray'
/home/me/ComputerGraphics/OpenGL1/01-triangles.cpp:35: undefined reference to `gl3wCreateBuffers'
/home/me/ComputerGraphics/OpenGL1/01-triangles.cpp:36: undefined reference to `gl3wBindBuffer'
/home/me/ComputerGraphics/OpenGL1/01-triangles.cpp:37: undefined reference to `gl3wBufferStorage'
/home/me/ComputerGraphics/OpenGL1/01-triangles.cpp:46: undefined reference to `LoadShaders'
......

我以前曾认为它与vulkan有关,但现在我添加了-ldl,并且错误仍然存​​在.那么,如何在NetBeans中的Linux上成功编译triangles.cpp代码?非常感谢.

I had previously thought it is related to vulkan but now I have added -ldl and the errors persist. So, how can I successfully compile the triangles.cpp code on linux within NetBeans? Thank a lot.

推荐答案

事实证明,除了GLFW之外,我还需要一个库GL3W.请遵循以下步骤(基于我已经在NetBeans中设置的设置):

It turns out I need one more library GL3W in addition to GLFW. Follow these steps (based on the settings I have set already in NetBeans):

(1)转到 https://github.com/shakesoda/gl3w 安装GL3W ,或使用随书附带的现有文件.

(1) Go to https://github.com/shakesoda/gl3w to install GL3W, or use existing files shipped with the book.

(2)将链接器标志设置为:

(2) Set the linker flag to:

-pthread -ldl -lGLU -lGL -lrt -lXrandr -lXxf86vm -lXi -lXinerama -lX11 -lXcursor

注意:以前的线程中没有提到 -ldl -lXcursor 标志,但确实需要.

Note: the -ldl and -lXcursor flags are not mentioned in previous threads but indeed needed.

(3)将gl3w.c和LoadShaders.cpp添加到源文件中

(3) Add gl3w.c and LoadShaders.cpp to the Source Files

(4)在LoadShaders.cpp的开头添加#include <cstdio>

(4) Add #include <cstdio> at the beginning of LoadShaders.cpp

(5)编译完成!

这篇关于如何在NetBeans 8.1中进行设置以成功编译使用GLFW的OpenGL代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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