Setting up OpenGL NetBeans project with GLFW on Ub

2020-04-10 03:37发布

问题:

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 :

undefined reference to `glfwInit' error while running this simple code:

#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;
}

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]: 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 functionglfwOpenWindow': /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 functiontranslateKey': /usr/lib/libglfw.a(x11_window.o): In function translateKey': /usr/lib/libglfw.a(x11_window.o): In functiontranslateChar': ........... ........................

What else should I link or install?

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.

Update1 Compiling the main.cpp manually using this command:

**g++ main.cpp  -o Game -lglfw -lGL -lGLU -lX11 -lpthread -lXxf86vm -lm**

Compiles fine.How do I link all these libs via NetBeans???

回答1:

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

I guess lGLU is needed only if you use the old OpenGL version.