Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. Linking OpenGL Lib for MinGW and Visual Studio

Linking OpenGL Lib for MinGW and Visual Studio

Scheduled Pinned Locked Moved Solved Qt Creator and other tools
5 Posts 2 Posters 3.9k 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.
  • S Offline
    S Offline
    stvokr
    wrote on last edited by
    #1

    Hi all,

    I am using (or I have to use) MinGW and Visual Studio compiler for the same project (Windows 10, Qt 5.6.1, MinGW 4.9.2, MSVC2015).
    I can compile my project on linux, so this is not a problem.
    I have to add tje OpenGL Lib to the project on Windows, otherwise it doesn't link. I used to use MSVC with the following setting:

    win32:LIBS += opengl32.lib    # for visual studio
    

    Now I want to use MinGW in addition to the MSVC2015. And therefore I have to change this code:

    win32:LIBS += libopengl32     # for mingw
    

    But this collides with the MSVC2015, because this isn't working for both linkers at the same time.

    win32:LIBS += -Lopengl32      # doesn't work either, for both.
    

    It's kind of funny, because on Linux "LIBS += libopengl32" is not necessary.

    Is there any kind of seperation of compilers or kits in the pro file?
    Does anyone have an idea?

    Kind regards
    Oliver

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      What do you mean by you have to use both for the same project ? Do you mean get it to compile entirely with each them or trying to build parts of your project with each ?

      In any case, you shouldn't need to explicitly add the OpenGL library since Qt uses them already and will link your application accordingly.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • S Offline
        S Offline
        stvokr
        wrote on last edited by
        #3

        Hi,

        I mean I have to compile the entire project with different compilers, so I have two builds of the project each running with another Qt runtime library.

        I use OpenGL in my application like this.
        My class:

        class GLWidget : public QOpenGLWidget, protected QOpenGLFunctions
        

        My code:

        glLineWidth( 1.0f );
        glColor3f( color.red() / 255.0, color.green() / 255.0, color.blue() / 255.0 );
        
        glBegin( GL_LINE_STRIP );
        for( int j = 0; j < polyline->count(); j++ )
        {
            glVertex2f( polyline->at( j ).x(), polyline->at( j ).y() );
        }
        glEnd();
        

        When I remove "win32:LIBS += opengl32.lib" I get these linker errors (and more). So I think it is necessary on Windows, but it is not on Linux. It would be nice if it would not be necessary for Windows.

        plotter.obj : error LNK2019: unresolved external symbol __imp__glBegin@4 referenced in function "public: void __thiscall GLWidget::drawDistanceLine(class QPointF,class QPointF,class QColor,class QColor)" (?    drawDistanceLine@GLWidget@@QAEXVQPointF@@0VQColor@@1@Z)
        plotter.obj : error LNK2019: unresolved external symbol __imp__glColor3f@12 referenced in function "public: void __thiscall GLWidget::drawDistanceLine(class QPointF,class QPointF,class QColor,class QColor)" (?drawDistanceLine@GLWidget@@QAEXVQPointF@@0VQColor@@1@Z)
        

        Any explanations?

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          AFAIK, glBegin is part of the fixed pipeline so if you want to use it you need to inherit from another set of QOpenGLFunctions.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • S Offline
            S Offline
            stvokr
            wrote on last edited by
            #5

            Thanks,

            I inherit from QOpenGLFunctions_3_0 and that works for me.

            1 Reply Last reply
            0

            • Login

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