Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

link GLFW and GLEW to QT-Creator

I wanted to learn OpenGl with Cpp using QT-Creator but it seems that i didn't linked my GLFW lib right.

I used

sudo apt-get install libglfw3 libglfw3-dev libglfw3-doc

and

sudo apt-get install libglew-dbg libglew-dev libglew1.13

to install them and afterwards, the QT_Creator "showed" me

//GLEW
#include "GL/glew.h"
//GLFW
#include "GLFW/glfw3.h"

so I thought, I could use them, but i got an "undifened reference to ...". I already looked at this question, but it doesn't seem to work. And I never worked with CMake or qmake before, so i can't see my mistake.

like image 330
streber Avatar asked Sep 04 '25 01:09

streber


1 Answers

I can provide my enviroment setup notes for you, or you can read it from my sites, But prevent my site url from invalid someday, I rewrite it here.

Install glfw

  1. First. we need to install dependencies on ubuntu

    sudo apt-get install xorg-dev
    sudo apt-get install libglu1-mesa-dev
    

Install glew

  1. Then download source package at official

  2. Extract your package and open your terminal, then cd to what your package location which you just extracted.

  3. Do following commnad to install

    make extension
    make 
    sudo make install
    sudo make clean
    

Open QT project and set opengl settings

  1. Open a console project in QT

  2. Add following settings in your .pro file anywhere.

    LIBS +=-lGLEW -lglfw3 -lGL -lX11 -lXi -lXrandr -lXxf86vm -lXinerama -lXcursor -lrt -lm -pthread
    

Try a simple test.

#define GLEW_STATIC
#include <GL/glew.h>
#include<GLFW/glfw3.h>

int main(int argc, char *argv[])
{
    glfwInit();
    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
    glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
    glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);
    return 0;
}

Enjoy it

like image 158
Tokenyet Avatar answered Sep 13 '25 14:09

Tokenyet