QT OpenGL链接错误
QT OpenGL Link Error
我在Windows上的QT Creator中编译OpenGL QT项目时遇到了一个错误。
我得到的错误是链接错误。
我已经尝试重新运行qmake,然后进行清理和构建,但这并没有解决问题。我也尝试了一些其他的建议从stackoverflow问题类似于我的,但没有解决这个问题
我将包括链接错误和我的项目代码下面。
提前感谢!
链接错误:
17:38:04: Running steps for project OpenGL2...
17:38:04: Configuration unchanged, skipping qmake step.
17:38:04: Starting: "C:QtToolsQtCreatorbinjom.exe"
C:QtToolsQtCreatorbinjom.exe -f Makefile.Debug
C:Qt5.6msvc2013_64binuic.exe ..mainwindow.ui -o ui_mainwindow.h
cl -c -nologo -Zc:wchar_t -FS -Zi -MDd -GR -W3 -w34100 -w34189 -w44996 -EHsc /FddebugOpenGL2.pdb -DUNICODE -DWIN32 -DWIN64 -DQT_QML_DEBUG -DQT_OPENGL_LIB -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -I....OpenGL2 -I. -IC:Qt5.6msvc2013_64include -IC:Qt5.6msvc2013_64includeQtOpenGL -IC:Qt5.6msvc2013_64includeQtWidgets -IC:Qt5.6msvc2013_64includeQtGui -IC:Qt5.6msvc2013_64includeQtANGLE -IC:Qt5.6msvc2013_64includeQtCore -Idebug -I. -IC:Qt5.6msvc2013_64mkspecswin32-msvc2013 -Fodebug @C:UserscontextAppDataLocalTempmain.obj.9848.16.jom
cl -c -nologo -Zc:wchar_t -FS -Zi -MDd -GR -W3 -w34100 -w34189 -w44996 -EHsc /FddebugOpenGL2.pdb -DUNICODE -DWIN32 -DWIN64 -DQT_QML_DEBUG -DQT_OPENGL_LIB -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -I....OpenGL2 -I. -IC:Qt5.6msvc2013_64include -IC:Qt5.6msvc2013_64includeQtOpenGL -IC:Qt5.6msvc2013_64includeQtWidgets -IC:Qt5.6msvc2013_64includeQtGui -IC:Qt5.6msvc2013_64includeQtANGLE -IC:Qt5.6msvc2013_64includeQtCore -Idebug -I. -IC:Qt5.6msvc2013_64mkspecswin32-msvc2013 -Fodebug @C:UserscontextAppDataLocalTempmainwindow.obj.9848.32.jom
C:Qt5.6msvc2013_64binmoc.exe -DUNICODE -DWIN32 -DWIN64 -DQT_QML_DEBUG -DQT_OPENGL_LIB -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -D_MSC_VER=1800 -D_WIN32 -D_WIN64 -IC:/Qt/5.6/msvc2013_64/mkspecs/win32-msvc2013 -IC:/Users/context/Documents/OpenGL2 -IC:/Qt/5.6/msvc2013_64/include -IC:/Qt/5.6/msvc2013_64/include/QtOpenGL -IC:/Qt/5.6/msvc2013_64/include/QtWidgets -IC:/Qt/5.6/msvc2013_64/include/QtGui -IC:/Qt/5.6/msvc2013_64/include/QtANGLE -IC:/Qt/5.6/msvc2013_64/include/QtCore -I. ..mainwindow.h -o debugmoc_mainwindow.cpp
main.cpp
mainwindow.cpp
..mainwindow.cpp(3) : warning C4100: 'parent' : unreferenced formal parameter
..mainwindow.cpp(28) : warning C4100: 'h' : unreferenced formal parameter
..mainwindow.cpp(28) : warning C4100: 'w' : unreferenced formal parameter
..mainwindow.cpp(52) : warning C4100: 'event' : unreferenced formal parameter
..mainwindow.cpp(57) : warning C4100: 'event' : unreferenced formal parameter
cl -c -nologo -Zc:wchar_t -FS -Zi -MDd -GR -W3 -w34100 -w34189 -w44996 -EHsc /FddebugOpenGL2.pdb -DUNICODE -DWIN32 -DWIN64 -DQT_QML_DEBUG -DQT_OPENGL_LIB -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -I....OpenGL2 -I. -IC:Qt5.6msvc2013_64include -IC:Qt5.6msvc2013_64includeQtOpenGL -IC:Qt5.6msvc2013_64includeQtWidgets -IC:Qt5.6msvc2013_64includeQtGui -IC:Qt5.6msvc2013_64includeQtANGLE -IC:Qt5.6msvc2013_64includeQtCore -Idebug -I. -IC:Qt5.6msvc2013_64mkspecswin32-msvc2013 -Fodebug @C:UserscontextAppDataLocalTempmoc_mainwindow.obj.9848.718.jom
moc_mainwindow.cpp
link /NOLOGO /DYNAMICBASE /NXCOMPAT /DEBUG /SUBSYSTEM:WINDOWS "/MANIFESTDEPENDENCY:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' publicKeyToken='6595b64144ccf1df' language='*' processorArchitecture='*'" /MANIFEST:embed /OUT:debugOpenGL2.exe @C:UserscontextAppDataLocalTempOpenGL2.exe.9848.4400.jom
**mainwindow.obj : error LNK2019: unresolved external symbol __imp_glBegin referenced in function "protected: virtual void __cdecl MainWindow::paintGL(void)" (?paintGL@MainWindow@@MEAAXXZ)
mainwindow.obj : error LNK2019: unresolved external symbol __imp_glClear referenced in function "protected: virtual void __cdecl MainWindow::paintGL(void)" (?paintGL@MainWindow@@MEAAXXZ)
mainwindow.obj : error LNK2019: unresolved external symbol __imp_glClearColor referenced in function "protected: virtual void __cdecl MainWindow::paintGL(void)" (?paintGL@MainWindow@@MEAAXXZ)
mainwindow.obj : error LNK2019: unresolved external symbol __imp_glEnd referenced in function "protected: virtual void __cdecl MainWindow::paintGL(void)" (?paintGL@MainWindow@@MEAAXXZ)
mainwindow.obj : error LNK2019: unresolved external symbol __imp_glFlush referenced in function "protected: virtual void __cdecl MainWindow::paintGL(void)" (?paintGL@MainWindow@@MEAAXXZ)
mainwindow.obj : error LNK2019: unresolved external symbol __imp_glVertex2f referenced in function "protected: virtual void __cdecl MainWindow::paintGL(void)" (?paintGL@MainWindow@@MEAAXXZ)
debugOpenGL2.exe : fatal error LNK1120: 6 unresolved externals
jom: C:UserscontextDocumentsOpenGL2buildMakefile.Debug [debugOpenGL2.exe] Error 1120**
jom: C:UserscontextDocumentsOpenGL2buildMakefile [debug] Error 2
17:38:09: The process "C:QtToolsQtCreatorbinjom.exe" exited with code 2.
Error while building/deploying project OpenGL2 (kit: Desktop Qt 5.6.1 MSVC2013 64bit2)
When executing step "Make"
下面是我的代码和配置文件:
OpenGL2.pro
QT += core gui opengl
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = OpenGL2
TEMPLATE = app
SOURCES += main.cpp
mainwindow.cpp
HEADERS += mainwindow.h
FORMS += mainwindow.ui
mainwindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QOpenGLWindow>
#include <QSurfaceFormat>
#include <QOpenGLFunctions>
#include <QtOpenGL>
#include <GL/glu.h>
class MainWindow : public QOpenGLWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
protected:
virtual void initializeGL();
virtual void resizeGL(int w, int h);
virtual void paintGL();
void paintEvent(QPaintEvent *event);
void resizeEvent(QResizeEvent *event);
private:
QOpenGLContext* context;
QOpenGLFunctions* openGLFunctions;
};
main.cpp
#include "mainwindow.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.setTitle("OpenGL Hello World!");
w.resize(640, 480);
w.show();
return a.exec();
}
mainwindow.cpp
#include "mainwindow.h"
MainWindow::MainWindow(QWidget *parent)
{
setSurfaceType(QWindow::OpenGLSurface);
QSurfaceFormat format;
format.setProfile(QSurfaceFormat::CompatibilityProfile);
format.setVersion(2, 1); // OpenGL 2.1
setFormat(format);
context = new QOpenGLContext;
context->setFormat(format);
context->create();
context->makeCurrent(this);
openGLFunctions = context->functions();
}
MainWindow::~MainWindow()
{
}
void MainWindow::initializeGL()
{
}
void MainWindow::resizeGL(int w, int h)
{
}
void MainWindow::paintGL()
{
// Initialize clear color (cornflower blue)
glClearColor(0.39f, 0.58f, 0.93f, 1.f);
// Clear color buffer
glClear(GL_COLOR_BUFFER_BIT);
// Hello World
// Render quad
glBegin(GL_QUADS);
glVertex2f(-0.5f, -0.5f);
glVertex2f(0.5f, -0.5f);
glVertex2f(0.5f, 0.5f);
glVertex2f(-0.5f, 0.5f);
glEnd();
glFlush();
}
void MainWindow::paintEvent(QPaintEvent *event)
{
paintGL();
}
void MainWindow::resizeEvent(QResizeEvent *event)
{
}
这些是OpenGL函数,你需要链接到OpenGL32.lib。将此添加到.pro文件中:
LIBS += -lOpenGL32
相关文章:
- Netbeans 10:错误:链接器命令失败,退出代码为 1(使用 -v 查看调用)
- CMake 错误:链接器命令失败,退出代码为 1 和 cpp.o 文件
- clang:错误:链接器命令失败,退出代码为 1(使用 -v 查看调用) - 体系结构的未定义符号 x86_64:
- 如何修复 clang: 错误:链接器命令失败,退出代码为 1(使用 -v 查看调用)
- Android NDK.Build命令失败.未定义的引用.clang++:错误:链接器命令失败,退出代码为1
- 使用cmake错误链接boost日志
- 错误:链接器命令失败,退出代码为 1(使用 -v 查看调用):在 Macbook 上
- C++ XCODE ld:找不到体系结构x86_64 clang 的符号:错误:链接器命令失败,退出代码为 1(使用 -
- clang:错误:链接器命令失败,C++代码中的退出代码为 1(使用 -v 查看调用)
- 静态库中的 g++ 错误链接函数
- 未定义的参考错误链接天然函数Android
- C++编译错误:ld:找不到体系结构x86_64 clang 的符号:错误:链接器命令失败,退出代码为 1(使用 -v
- QT Q_PROPERTY错误:链接器命令失败,退出代码为 1(使用 -v 查看调用)
- ld:找不到体系结构x86_64 clang 的符号:错误:链接器命令失败,退出代码为 1(使用 -v 查看调用)
- OSX MOJAVE -LD:架构X86_64 clang找不到符号:错误:链接器命令失败,出口代码1
- C 错误链接器命令失败了出口代码1(使用-V查看调用)
- LD:架构x86_64 clang找不到符号:错误:链接器命令失败,出口代码1(使用-v to See
- 聚输出错误 - 链接列表
- Xcode链接器错误:链接器命令失败,退出代码为1(使用-v查看调用)
- 尝试构建C DLIB示例无法与数百个未定义的参考错误链接