Qt + OpenGL - Проблема с использованием opengl в Qt

Я начинающий и захотел улучшить свои навыки, создав простую игру в qt с использованием OpenGL, но после написания некоторого кода я столкнулся с множеством ошибок. Есть идея, что у меня просто нет самой библиотеки. Для этого, как я понимаю, можно скачать glfw и затем подключить файлы, которые хранятся в папке lib-mingw, но при установке и распаковке у меня этой папки нет (все, что есть: docs, include, lib-mingw-w64, lib-static-urct, lib- vc2012... lib-vc2022), а lib-mingw-w64, похоже, не подходит. В общем, прошу вас просветить и, если не сложно, порекомендовать что-нибудь для изучения qt и opengl

файл socoban.pro:

QT       += core gui opengl

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

CONFIG += c++17
CONFIG += qt6

SOURCES += \
    main.cpp \
    socoban.cpp

HEADERS += \
    socoban.hpp

FORMS +=
LIBS += -lglu32 -lopengl32
# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target

файл socoBAN.hpp:

#ifndef SOCOBAN_HPP
#define SOCOBAN_HPP

#include <QtOpenGLWidgets/QOpenGLWidget>
#include <QOpenGLFunctions>

class socoban :  public QOpenGLWidget, protected QOpenGLFunctions
{
    Q_OBJECT
public:
    socoban();
    ~socoban();
protected:
    void initializeGL() override;
    void resizeGL(int, int) override;
    void paintGL() override;
};

#endif // SOCOBAN_HPP

файл main.cpp:

#include <QApplication>

#include <socoban.hpp>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    socoban app;
    app.show();

    return a.exec();
}

файл socoban.cpp:

socoban::socoban()
{}
socoban:: ~socoban()
{}

void socoban:: initializeGL()
{
    /*glDisable(GL_DEPTH_TEST);

    glEnable(GL_BLEND);
    glEnable(GL_LINE_SMOOTH);
    glEnable(GL_POINT_SMOOTH);
    glEnable(GL_SMOOTH);
    glEnable(GL_TEXTURE_2D);

    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);*/
}
void socoban:: resizeGL(int aW, int aH)
{
    /*glLoadIdentity();
    glViewport(0, 0, (GLint)aW, (GLint)aH);
    glOrtho(0,600, 800, 0, 0, 1);*/
}
void socoban:: paintGL()
{
    /*glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glClearColor(0.0f, 0.0f, 0.0f, 1.0f);*/
}

Ошибки:

  1. debug/socoban.o: in function `socoban::socoban()':

  2. C:\Qt\SokoBAN\socoban.cpp:3: error: undefined reference to `__imp__ZN13QOpenGLWidgetC2EP7QWidget6QFlagsIN2Qt10WindowTypeEE'

3):-1: error: C:\Qt\build-SokoBAN-Desktop_Qt_6_6_2_MinGW_64_bit-Debug/../SokoBAN/socoban.cpp:4: undefined reference to `__imp__ZN13QOpenGLWidgetD2Ev'

4):-1: error: debug/socoban.o: in function `socoban::~socoban()':

5)C:\Qt\SokoBAN\socoban.cpp:6: error: undefined reference to `__imp__ZN13QOpenGLWidgetD2Ev'

6):-1: error: debug/moc_socoban.o: in function `socoban::qt_metacast(char const*)':

7)C:\Qt\build-SokoBAN-Desktop_Qt_6_6_2_MinGW_64_bit-Debug\debug\moc_socoban.cpp:109: error: undefined reference to `__imp__ZN13QOpenGLWidget11qt_metacastEPKc'

8):-1: error: debug/moc_socoban.o: in function `socoban::qt_metacall(QMetaObject::Call, int, void**)':

9)C:\Qt\build-SokoBAN-Desktop_Qt_6_6_2_MinGW_64_bit-Debug\debug\moc_socoban.cpp:114: error: undefined reference to `__imp__ZN13QOpenGLWidget11qt_metacallEN11QMetaObject4CallEiPPv'

10):-1: error: debug/moc_socoban.o: in function `QMetaObject const* QMetaObject::staticMetaObjectQOpenGLWidget::staticMetaObject()':

11)C:\Qt\6.6.2\mingw_64\include\QtCore\qobjectdefs.h:486: error: undefined reference to `__imp__ZN13QOpenGLWidget16staticMetaObjectE'

12):-1: error: debug/moc_socoban.o:moc_socoban.cp:(.rdata$_ZTV7socoban[_ZTV7socoban]+0x38): undefined reference to `QOpenGLWidget::event(QEvent*)'

13):-1: error: debug/moc_socoban.o:moc_socoban.cp:(.rdata$_ZTV7socoban[_ZTV7socoban]+0xa0): undefined reference to `QOpenGLWidget::paintEngine() const'

14):-1: error: debug/moc_socoban.o:moc_socoban.cp:(.rdata$_ZTV7socoban[_ZTV7socoban]+0x100): undefined reference to `QOpenGLWidget::paintEvent(QPaintEvent*)'

15):-1: error: debug/moc_socoban.o:moc_socoban.cp:(.rdata$_ZTV7socoban[_ZTV7socoban]+0x110): undefined reference to `QOpenGLWidget::resizeEvent(QResizeEvent*)'

16):-1: error: debug/moc_socoban.o:moc_socoban.cp:(.rdata$_ZTV7socoban[_ZTV7socoban]+0x178): undefined reference to `QOpenGLWidget::metric(QPaintDevice::PaintDeviceMetric) const'

17):-1: error: debug/moc_socoban.o:moc_socoban.cp:(.rdata$_ZTV7socoban[_ZTV7socoban]+0x188): undefined reference to `QOpenGLWidget::redirected(QPoint*) const'

18):-1: error: debug/moc_socoban.o:moc_socoban.cp:(.rdata$_ZTV7socoban[_ZTV7socoban]+0x1f0): undefined reference to `non-virtual thunk to QOpenGLWidget::paintEngine() const'

19):-1: error: debug/moc_socoban.o:moc_socoban.cp:(.rdata$_ZTV7socoban[_ZTV7socoban]+0x1f8): undefined reference to `non-virtual thunk to QOpenGLWidget::metric(QPaintDevice::PaintDeviceMetric) const'

20):-1: error: debug/moc_socoban.o:moc_socoban.cp:(.rdata$_ZTV7socoban[_ZTV7socoban]+0x208): undefined reference to `non-virtual thunk to QOpenGLWidget::redirected(QPoint*) const'

21):-1: error: collect2.exe: error: ld returned 1 exit status

22):-1: error: [Makefile.Debug:72: debug/SokoBAN.exe] Error 1


Ответы (0 шт):