Linking OpenGL Lib for MinGW and Visual Studio



  • 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


  • Lifetime Qt Champion

    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.



  • 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?


  • Lifetime Qt Champion

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



  • Thanks,

    I inherit from QOpenGLFunctions_3_0 and that works for me.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.