error LNK2019: unresolved external symbol __imp_glBegin referenced in ... (I have both Qt OpenGL & QtOpenGLWidget modules included)
-
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:
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!
-
You need to link against the opengl libraries. Opemgl32.lib on windows.
-
You need to link against the opengl libraries. Opemgl32.lib on windows.
@Christian-Ehrlicher Where do we find those libs?
-
@Christian-Ehrlicher thanks. That worked! Here is a screenshot for future users of where to add it:
-
E enjoysmath has marked this topic as solved on