Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. error LNK2019: unresolved external symbol __imp_glBegin referenced in ... (I have both Qt OpenGL & QtOpenGLWidget modules included)

error LNK2019: unresolved external symbol __imp_glBegin referenced in ... (I have both Qt OpenGL & QtOpenGLWidget modules included)

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 2 Posters 181 Views
  • 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.
  • enjoysmathE Offline
    enjoysmathE Offline
    enjoysmath
    wrote on last edited by
    #1

    This is in Visual Studio Community 2022 (64-bit) - Current. The C++ Version is Visual C++ 2022. I'm using the latest C++ release version (so past C++ 20).

    Here is a screenshot of my module selection:

    40ef0967-1e2f-417b-9101-5ce0447453aa-image.png

    Here is glviewwidget.h:

    #pragma once
    #include <QOpenGLWidget>
    #include <QOpenGLFunctions>
    #include "glgraphicsitem.h"
    #include <QColor>
    #include <QList>
    
    
    class GLViewWidget : public QOpenGLWidget, protected QOpenGLFunctions
    {
    public:
    	GLViewWidget(QWidget* parent = nullptr);
    
    protected:
    	void initializeGL() override;
    	void paintGL() override;
    	void resizeGL(int w, int h) override;
    	void perspective(GLdouble fovy, GLdouble aspect, GLdouble zNear, GLdouble zFar);
    	void setBackgroundColor(char r, char g, char b, char a);
    	QColor backgroundColor() const { return bgColor; }
    	void addItem(GLGraphicsItem* gfxItem);
    
    private slots:
    	void updateRequestedByItem() { update(); }
    
    private:
    	QList<GLGraphicsItem*> graphicsItems;
    	QColor bgColor;
    };
    

    And its implementation glviewwidget.cpp:
    #include "glviewwidget.h":

    GLViewWidget::GLViewWidget(QWidget* parent)
    	: QOpenGLWidget(parent)
    {
    }
    
    void GLViewWidget::initializeGL()
    {
    	initializeOpenGLFunctions();	
    	glEnable(GL_DEPTH_TEST);
    }
    
    void GLViewWidget::paintGL()
    {
    	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    	glLoadIdentity();
    
    	foreach(auto const& item, graphicsItems)
    	{
    		item->paintGL();
    	}
    }
    
    void GLViewWidget::resizeGL(int w, int h)
    {
    	glViewport(0, 0, w, h);
    	glMatrixMode(GL_PROJECTION);
    	glLoadIdentity();
    	// The below line replaces gluPerspective(45.0, (float)w / (float)h, 0.1, 100.0);
    	// TODO: are the params correct? -ddj
    	perspective(45.0, 1.0f, 0.1, 100.0);
    	glMatrixMode(GL_MODELVIEW);
    }
    
    void GLViewWidget::perspective(GLdouble fovy, GLdouble aspect, GLdouble zNear, GLdouble zFar)
    {
    	GLdouble top = zNear * tan(fovy * M_PI / 360.0);
    	GLdouble right = top * aspect;
    	glFrustum(-right, right, -top, top, zNear, zFar);
    }
    
    void GLViewWidget::setBackgroundColor(char r, char g, char b, char a)
    {
    	bgColor.setRed(r);
    	bgColor.setGreen(g);
    	bgColor.setBlue(b);
    	bgColor.setAlpha(a);
    }
    
    void GLViewWidget::addItem(GLGraphicsItem* gfxItem)
    {
    	graphicsItems.append(gfxItem);
    	connect(gfxItem, &GLGraphicsItem::update, this, &GLViewWidget::updateRequestedByItem);
    	update();
    }
    

    The errors I'm getting are linker errors:

    1>glgriditem.obj : error LNK2019: unresolved external symbol __imp_glBegin referenced in function "protected: virtual void __cdecl GLGridItem::paintGL(void)" (?paintGL@GLGridItem@@MEAAXXZ)
    1>glgriditem.obj : error LNK2019: unresolved external symbol __imp_glEnd referenced in function "protected: virtual void __cdecl GLGridItem::paintGL(void)" (?paintGL@GLGridItem@@MEAAXXZ)
    1>glgriditem.obj : error LNK2019: unresolved external symbol __imp_glVertex3f referenced in function "protected: virtual void __cdecl GLGridItem::paintGL(void)" (?paintGL@GLGridItem@@MEAAXXZ)
    1>glviewwidget.obj : error LNK2019: unresolved external symbol __imp_glFrustum referenced in function "protected: void __cdecl GLViewWidget::perspective(double,double,double,double)" (?perspective@GLViewWidget@@IEAAXNNNN@Z)
    1>glviewwidget.obj : error LNK2019: unresolved external symbol __imp_glLoadIdentity referenced in function "protected: virtual void __cdecl GLViewWidget::paintGL(void)" (?paintGL@GLViewWidget@@MEAAXXZ)
    1>glviewwidget.obj : error LNK2019: unresolved external symbol __imp_glMatrixMode referenced in function "protected: virtual void __cdecl GLViewWidget::resizeGL(int,int)" (?resizeGL@GLViewWidget@@MEAAXHH@Z)
    1>debug\\cuberhiwidget.exe : fatal error LNK1120: 6 unresolved externals
    1>Done building project "cuberhiwidget.vcxproj" -- FAILED.
    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
    ========== Build completed at 9:38 AM and took 38.090 seconds ==========
    

    I know I'm coding this using the "old GL style", if you recommend using the "new GL style" or even Qt3D, I will try to learn those. But if I could simply get these linker errors fixed, I would prefer that. It's not a very complex scene that I'm rendering. Something like: a floor grid, a bounding box, and a scatter plot of up to 1000 points, all in 3D, with a camera to rotate around the scatter plot.

    Thanks for your help, in advance!

    https://github.com/enjoysmath
    https://math.stackexchange.com/users/26327/exercisingmathematician

    1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      You need to link against the opengl libraries. Opemgl32.lib on windows.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      enjoysmathE 1 Reply Last reply
      2
      • Christian EhrlicherC Christian Ehrlicher

        You need to link against the opengl libraries. Opemgl32.lib on windows.

        enjoysmathE Offline
        enjoysmathE Offline
        enjoysmath
        wrote on last edited by
        #3

        @Christian-Ehrlicher Where do we find those libs?

        https://github.com/enjoysmath
        https://math.stackexchange.com/users/26327/exercisingmathematician

        1 Reply Last reply
        0
        • enjoysmathE Offline
          enjoysmathE Offline
          enjoysmath
          wrote on last edited by
          #4

          @Christian-Ehrlicher thanks. That worked! Here is a screenshot for future users of where to add it:

          image.png

          https://github.com/enjoysmath
          https://math.stackexchange.com/users/26327/exercisingmathematician

          1 Reply Last reply
          0
          • enjoysmathE enjoysmath has marked this topic as solved on

          • Login

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