问题描述
我正在尝试在Ubuntu上设置OpenGL开发环境.我已经安装了包括GLFW在内的所有库,因为我不想使用GLUT.GLEW库也已安装.我正在尝试在NetBeans中设置所有库.以前从未使用过它,现在我得到了:
I am trying to setup OpenGL developing environment on Ubuntu.I installed all the libs including GLFW as I don't want to use GLUT.GLEW lib has been installed too.I am trying to set it all in NetBeans.I have never used it before and currently I am getting :
对`glfwInit'的未定义引用错误:
#include <stdio.h>
#include <cstdlib>
#include <iostream>
#include <GL/glew.h>
#include <GL/glfw.h>
#include "glm.hpp"
using namespace std;
using namespace glm;
int main(int argc, char** argv) {
/* init GLFW */
if(!glfwInit()){
fprintf(stderr,"failed to init GLFW");
}
return 0;
}
我确定这是与链接器相关的问题.因此我将libglfw.a添加到了Linker-> Libraries,然后出现了更多类似以下的错误:
I am sure it is linker related problem.So I have added libglfw.a to Linker->Libraries and then got even more errors like these:
make [2]:进入目录/home/sasmaster/NetBeansProjects/OpenGLDemo'mkdir -p dist/Debug/GNU-Linux-x86 g++ -o dist/Debug/GNU-Linux-x86/opengldemo build/Debug/GNU-Linux-x86/main.o /usr/lib/libglfw.a/usr/lib/libglfw.a(window.o): In function
glfwOpenWindow':/usr/lib/libglfw.a(x11_init.o):在函数_glfwPlatformInit':/usr/lib/libglfw.a(x11_init.o): In function
_glfwPlatformInit'中:/usr/lib/libglfw.a(x11_init.o):在函数_glfwPlatformInit':/usr/lib/libglfw.a(x11_init.o): In function
_glfwPlatformInit'中:/usr/lib/libglfw.a(x11_init.o):在函数_glfwPlatformTerminate':/usr/lib/libglfw.a(x11_init.o): In function
_glfwPlatformTerminate'中:/usr/lib/libglfw.a(x11_window.o):在函数translateKey':/usr/lib/libglfw.a(x11_window.o): In function
translateKey'中:/usr/lib/libglfw.a(x11_window.o):在函数translateKey':/usr/lib/libglfw.a(x11_window.o): In function
translateChar'中:..............................
make[2]: Entering directory /home/sasmaster/NetBeansProjects/OpenGLDemo'mkdir -p dist/Debug/GNU-Linux-x86 g++ -o dist/Debug/GNU-Linux-x86/opengldemo build/Debug/GNU-Linux-x86/main.o /usr/lib/libglfw.a/usr/lib/libglfw.a(window.o): In function
glfwOpenWindow':/usr/lib/libglfw.a(x11_init.o): In function _glfwPlatformInit':/usr/lib/libglfw.a(x11_init.o): In function
_glfwPlatformInit':/usr/lib/libglfw.a(x11_init.o): In function _glfwPlatformInit':/usr/lib/libglfw.a(x11_init.o): In function
_glfwPlatformInit':/usr/lib/libglfw.a(x11_init.o): In function _glfwPlatformTerminate':/usr/lib/libglfw.a(x11_init.o): In function
_glfwPlatformTerminate':/usr/lib/libglfw.a(x11_window.o): In function translateKey':/usr/lib/libglfw.a(x11_window.o): In function
translateKey':/usr/lib/libglfw.a(x11_window.o): In function translateKey':/usr/lib/libglfw.a(x11_window.o): In function
translateChar':...................................
我还应该链接或安装什么?
What else should I link or install?
更新:此处,据说应该添加LIBRARIES ='- pthread -lglfw -lGL -lX11 -lGLU -lXxf86vm'但是我应该在NetBeans属性中添加那些内容呢?我也尝试过放入MakeFile和链接器选项",但没有任何帮助.
Update:Here it is said one should add LIBRARIES='-pthread -lglfw -lGL -lX11 -lGLU -lXxf86vm'But where should I add those in NetBeans properties? I tried put into the MakeFile and "linker options" too and nothing helped.
更新1 使用以下命令手动编译main.cpp:
Update1Compiling the main.cpp manually using this command:
**g++ main.cpp -o Game -lglfw -lGL -lGLU -lX11 -lpthread -lXxf86vm -lm**
编译良好.如何通过NetBeans链接所有这些库?
Compiles fine.How do I link all these libs via NetBeans???
推荐答案
我想出了解决方案.对于那些感兴趣的人:打开项目属性.然后链接器" -> 库" .在库"对话框中:点击添加选项" -> 其他选项" .在文本字段中插入以下参数:
I figured out the solution.For those interested:Openg Project properties.Then "Linker" ->"Libraries".In the Libraries dialog:Click "Add Option" -> "Other Option".In the textfield insert these params:
-lGLEW -lglfw -lGL -lGLU -lX11 -lpthread -lXxf86vm -lm
我猜只有在使用旧版OpenGL时才需要lGLU.
I guess lGLU is needed only if you use the old OpenGL version.
这篇关于在Ubuntu上使用GLFW设置OpenGL NetBeans项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!