opengl in linux via Qt creator

I am currently working in Ubuntu (mechanical beaver). And I decided to build the first program using opengl (just stupid window)


Via the "before downloading" library console

sudo apt-get install qtcreator libglfw3-dev libglm-dev libepoxy-dev libboost-all-dev libglew-dev

Here .about the file

TEMPLATE = app
CONFIG += console c++11
#CONFIG -= app_bundle
#CONFIG -= qt

QT += opengl

SOURCES += main.cpp

In here is the program itself , all the header files were connected without problems.

#include <iostream>
// Include standard headers
#include <stdio.h>
#include <stdlib.h>
// Include GLEW. Always include it before gl.h and glfw3.h, since it's a bit magic.
#include <GL/glew.h>
// Include GLFW
#include <GLFW/glfw3.h>
// Include GLM
#include <glm/glm.hpp>
using namespace glm;

using namespace std;

int main()
{
    // Initialise GLFW
     glewExperimental = true; // Needed for core profile
    if( !glfwInit() )
    {
        fprintf( stderr, "Failed to initialize GLFW\n" );
        return -1;
    }
    glfwWindowHint(GLFW_SAMPLES, 4); // 4x antialiasing
    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); // We want OpenGL 3.3
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
    glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); // To make MacOS happy; should not be needed
    glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); // We don't want the old OpenGL

    // Open a window and create its OpenGL context
    GLFWwindow* window; // (In the accompanying source code, this variable is global for simplicity)
    window = glfwCreateWindow( 1024, 768, "Tutorial 01", NULL, NULL);
    if( window == NULL ){
        fprintf( stderr, "Failed to open GLFW window. If you have an Intel GPU, they are not 3.3 compatible. Try the 2.1 version of the tutorials.\n" );
        glfwTerminate();
        return -1;
    }
    glfwMakeContextCurrent(window); // Initialize GLEW
    glewExperimental=true; // Needed in core profile
    if (glewInit() != GLEW_OK) {
        fprintf(stderr, "Failed to initialize GLEW\n");
        return -1;
    }
    // Ensure we can capture the escape key being pressed below
    glfwSetInputMode(window, GLFW_STICKY_KEYS, GL_TRUE);

    do{
        // Clear the screen. It's not mentioned before Tutorial 02, but it can cause flickering, so it's there nonetheless.
        glClear( GL_COLOR_BUFFER_BIT );

        // Draw nothing, see you in tutorial 2 !

        // Swap buffers
        glfwSwapBuffers(window);
        glfwPollEvents();

    } // Check if the ESC key was pressed or the window was closed
    while( glfwGetKey(window, GLFW_KEY_ESCAPE ) != GLFW_PRESS &&
           glfwWindowShouldClose(window) == 0 );

    return 0;
}

But for some reason it does not see the link

enter a description of the image here

What am I doing wrong ???

Author: Дух сообщества, 2019-05-07

3 answers

It looks like qmake doesn't put some library in the linker. Try specifying it manually. In the project:

LIBS += -lGLEW -lglfw -lOpenGL

Libraries are also added from the right-click menu on the. pro file -> Add Library. In the wizard that appears, select the necessary items. After that, the library should automatically register.

 1
Author: eri, 2019-05-08 10:06:45

The linker says that it can't resolve function references. You need to connect the appropriate library.

To connect a library in Qt Creator, right-click on the project, then "Add Library". Select the "External" type of the library to be compiled. Then select the library type "Linux (lib*. so lib*. a)". Select the library file and the path to the header file, the platform. Everything you need will be added to the .pro file.

 1
Author: Артём Зыктин, 2019-05-07 18:23:23

In general, I found where the files are, through the file manager Krusader, a file manager PCManFM I was let down and through the search did not show files with the extension .so

Added "external" libraries. They are located in the /usr/lib/x86_64-linux-gnu directory and the header files are located in the /usr/include

Now the .pro file looks like this:

TEMPLATE = app
CONFIG += console c++11
#CONFIG -= app_bundle
#CONFIG -= qt

QT += opengl

SOURCES += main.cpp

unix:!macx: LIBS += -L$$PWD/../../../usr/lib/x86_64-linux-gnu/ -lOpenGL

INCLUDEPATH += $$PWD/../../../usr/include/GL
DEPENDPATH += $$PWD/../../../usr/include/GL

unix:!macx: LIBS += -L$$PWD/../../../usr/lib/x86_64-linux-gnu/ -lGLEW

INCLUDEPATH += $$PWD/../../../usr/include/GL
DEPENDPATH += $$PWD/../../../usr/include/GL

unix:!macx: LIBS += -L$$PWD/../../../usr/lib/x86_64-linux-gnu/ -lglfw

INCLUDEPATH += $$PWD/../../../usr/include/GLFW
DEPENDPATH += $$PWD/../../../usr/include/GLFW

And everything worked :3 (main.cpp remained the same)

 0
Author: timob256, 2019-05-08 09:56:49