Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Game Development
  4. Can't compile simple source code working with OpenGL
Forum Updated to NodeBB v4.3 + New Features

Can't compile simple source code working with OpenGL

Scheduled Pinned Locked Moved Unsolved Game Development
2 Posts 1 Posters 7.5k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Z Offline
    Z Offline
    Zholaman
    wrote on 31 Mar 2016, 10:06 last edited by Zholaman
    #1

    Hi, please help.

    I can't compile simple source code working with OpenGL, taking from "Qt 5.3 Professional programming with C++" book (author Max Schlee).

    Every time when I build the source code I get the following errors:

    • D:\c++_project\build-OGLQuad-Desktop_Qt_5_5_1_MinGW_32bit-Debug\debug\OGLQuad.o:-1: In function `ZN7OGLQuad8resizeGLEii':
    • D:\c++_project\test9\OGLQuad.cpp:37: error: undefined reference to `_imp__glMatrixMode@4'
    • D:\c++_project\test9\OGLQuad.cpp:38: error: undefined reference to `_imp__glLoadIdentity@0'
    • D:\c++_project\test9\OGLQuad.cpp:39: error: undefined reference to `_imp__glViewport@16'
    • D:\c++_project\test9\OGLQuad.cpp:40: error: undefined reference to `_imp__glOrtho@48'
    • D:\c++_project\test9\OGLQuad.cpp:46: error: undefined reference to `_imp__glClear@4'
    • D:\c++_project\test9\OGLQuad.cpp:48: error: undefined reference to `_imp__glBegin@4']([link url]([link url](link url)))
      etc

    I use Qt 5.5.1, Qt Creator 3.6, MinGW 4.9.3 (32bit)

    My environment:
    OS Windows 7, 64bit.

    Source code of my project:

    pro file.

    TEMPLATE = app
    QT += widgets opengl core gui
    HEADERS = OGLQuad.h
    SOURCES = OGLQuad.cpp
    main.cpp
    windows:TARGET = ../OGLQuad

    main.cpp

    #include <QApplication>
    #include "OGLQuad.h"
    
    // ----------------------------------------------------------------------
    int main(int argc, char** argv)
    {
        QApplication app(argc, argv);
        OGLQuad      oglQuad;
    
        oglQuad.resize(200, 200);
        oglQuad.show();
    
        return app.exec();
    }
    

    OGLQuad.h

    #pragma once
    
    #include <QGLWidget>
    
    class OGLQuad : public QGLWidget {
    protected:
        virtual void initializeGL(                       );
        virtual void resizeGL    (int nWidth, int nHeight);
        virtual void paintGL     (                       );
    
    public:
        OGLQuad(QWidget* pwgt = 0);
    };
    

    OGLQuad.cpp

    #include "OGLQuad.h"
    
    // ----------------------------------------------------------------------
    OGLQuad::OGLQuad(QWidget* pwgt/*= 0*/) : QGLWidget(pwgt) 
    {
    }
    
    // ----------------------------------------------------------------------
    /*virtual*/void OGLQuad::initializeGL()
    {
        qglClearColor(Qt::black);
    }
    
    // ----------------------------------------------------------------------
    /*virtual*/void OGLQuad::resizeGL(int nWidth, int nHeight)
    {
        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        glViewport(0, 0, (GLint)nWidth, (GLint)nHeight);
        glOrtho(0, 100, 100, 0, -1, 1); 
    }
    
    // ----------------------------------------------------------------------
    /*virtual*/void OGLQuad::paintGL()
    {
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    
        glBegin(GL_QUADS);
            glColor3f(1, 0, 0); 
            glVertex2f(0, 100);
    
            glColor3f(0, 1, 0);
            glVertex2f(100, 100);
    
            glColor3f(0, 0, 1);
            glVertex2f(100, 0);
    
            glColor3f(1, 1, 1);
            glVertex2f(0, 0);
        glEnd();
    }
    

    Thanks

    Z 1 Reply Last reply 31 Mar 2016, 11:52
    0
    • Z Zholaman
      31 Mar 2016, 10:06

      Hi, please help.

      I can't compile simple source code working with OpenGL, taking from "Qt 5.3 Professional programming with C++" book (author Max Schlee).

      Every time when I build the source code I get the following errors:

      • D:\c++_project\build-OGLQuad-Desktop_Qt_5_5_1_MinGW_32bit-Debug\debug\OGLQuad.o:-1: In function `ZN7OGLQuad8resizeGLEii':
      • D:\c++_project\test9\OGLQuad.cpp:37: error: undefined reference to `_imp__glMatrixMode@4'
      • D:\c++_project\test9\OGLQuad.cpp:38: error: undefined reference to `_imp__glLoadIdentity@0'
      • D:\c++_project\test9\OGLQuad.cpp:39: error: undefined reference to `_imp__glViewport@16'
      • D:\c++_project\test9\OGLQuad.cpp:40: error: undefined reference to `_imp__glOrtho@48'
      • D:\c++_project\test9\OGLQuad.cpp:46: error: undefined reference to `_imp__glClear@4'
      • D:\c++_project\test9\OGLQuad.cpp:48: error: undefined reference to `_imp__glBegin@4']([link url]([link url](link url)))
        etc

      I use Qt 5.5.1, Qt Creator 3.6, MinGW 4.9.3 (32bit)

      My environment:
      OS Windows 7, 64bit.

      Source code of my project:

      pro file.

      TEMPLATE = app
      QT += widgets opengl core gui
      HEADERS = OGLQuad.h
      SOURCES = OGLQuad.cpp
      main.cpp
      windows:TARGET = ../OGLQuad

      main.cpp

      #include <QApplication>
      #include "OGLQuad.h"
      
      // ----------------------------------------------------------------------
      int main(int argc, char** argv)
      {
          QApplication app(argc, argv);
          OGLQuad      oglQuad;
      
          oglQuad.resize(200, 200);
          oglQuad.show();
      
          return app.exec();
      }
      

      OGLQuad.h

      #pragma once
      
      #include <QGLWidget>
      
      class OGLQuad : public QGLWidget {
      protected:
          virtual void initializeGL(                       );
          virtual void resizeGL    (int nWidth, int nHeight);
          virtual void paintGL     (                       );
      
      public:
          OGLQuad(QWidget* pwgt = 0);
      };
      

      OGLQuad.cpp

      #include "OGLQuad.h"
      
      // ----------------------------------------------------------------------
      OGLQuad::OGLQuad(QWidget* pwgt/*= 0*/) : QGLWidget(pwgt) 
      {
      }
      
      // ----------------------------------------------------------------------
      /*virtual*/void OGLQuad::initializeGL()
      {
          qglClearColor(Qt::black);
      }
      
      // ----------------------------------------------------------------------
      /*virtual*/void OGLQuad::resizeGL(int nWidth, int nHeight)
      {
          glMatrixMode(GL_PROJECTION);
          glLoadIdentity();
          glViewport(0, 0, (GLint)nWidth, (GLint)nHeight);
          glOrtho(0, 100, 100, 0, -1, 1); 
      }
      
      // ----------------------------------------------------------------------
      /*virtual*/void OGLQuad::paintGL()
      {
          glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
      
          glBegin(GL_QUADS);
              glColor3f(1, 0, 0); 
              glVertex2f(0, 100);
      
              glColor3f(0, 1, 0);
              glVertex2f(100, 100);
      
              glColor3f(0, 0, 1);
              glVertex2f(100, 0);
      
              glColor3f(1, 1, 1);
              glVertex2f(0, 0);
          glEnd();
      }
      

      Thanks

      Z Offline
      Z Offline
      Zholaman
      wrote on 31 Mar 2016, 11:52 last edited by
      #2

      @Zholaman For those who faced with this problem.

      I have resolved it by adding the following lib in my pro file:

      LIBS += -LD:\Qt\5.5\mingw492_32\lib\libQt5OpenGL.a -lopengl32

      The D:\Qt\5.5\mingw492_32\lib\libQt5OpenGL.a is path to lib file (libQt5OpenGL.a)

      1 Reply Last reply
      0

      1/2

      31 Mar 2016, 10:06

      • Login

      • Login or register to search.
      1 out of 2
      • First post
        1/2
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved