qt - 在 Qt 中使用 OpenGL 时出现链接器错误

标签 qt visual-c++ opengl linker

我正在尝试将 OpenGL 与 Qt 一起使用。 我正在关注这个例子:http://qt-project.org/doc/qt-5.0/qtgui/openglwindow.html使用适用于 msvc2012 的 Qt 5 构建。最后我收到以下错误:

  1. 错误 LNK2019:函数“public: virtual void __thiscall OpenGLWindow::render(void)”中引用了无法解析的外部符号 _imp_glClear@4 (?render@OpenGLWindow@@UAEXXZ) D:\文件\代码\Qt项目\qttest2\qttest2\openglwindow.obj qttest2
  2. 错误 LNK2001:无法解析的外部符号 _imp_glClear@4 D:\Documents\Code\Qt Projects\qttest2\qttest2\trianglewindow.obj qttest2
  3. 错误 LNK2019:函数“public: virtual void __thiscall TriangleWindow::render(void)”中引用了无法解析的外部符号 _imp_glDrawArrays@12 (?render@TriangleWindow@@UAEXXZ) D:\文件\代码\Qt项目\qttest2\qttest2\trianglewindow.obj qttest2
  4. 错误 LNK2019:函数“public: virtual void __thiscall TriangleWindow::render(void)”中引用了无法解析的外部符号 _imp_glViewport@16 (?render@TriangleWindow@@UAEXXZ) D:\文件\代码\Qt项目\qttest2\qttest2\trianglewindow.obj qttest2
  5. 错误 LNK1120:3 个无法解析的外部 D:\Documents\Code\Qt Projects\qttest2\Win32\Debug\qttest2.exe qttest2

我可以看到它与 OpenGL 函数的链接有关,但我对链接了解不多。

即使我从 OpenGLWindow 示例复制源代码,我也会收到错误。

最佳答案

您必须将opengl32.lib添加到链接库列表中。在 QtCreator .pro 文件中添加 OpenGL 模块应该可以解决问题

QT += opengl

关于qt - 在 Qt 中使用 OpenGL 时出现链接器错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14677304/

相关文章:

c++ - 使用 2 个 channel 编写自定义 QIODevice

c++ - 我可以检索包含非拉丁字符的路径吗?

c++ - 在 Windows 上测量 Opengl 的运行时间?

c++ - 将 QWidget 的屏蔽区域上的鼠标事件传输到它的父级

python - Pyqt5 已安装但在导入时出现 dll 加载失败错误?

C - ~ 是什么意思

c++ - VS2012中使用 'volatile'关键字的最佳实践

c++ - 使用 vsync (OpenGL) 时 CPU 利用率为 100%

OpenGL - 如何将 Sprite 的遮挡区域显示为轮廓

android - 如何删除 QCalendarWidget 中的选定日期矩形和小部件中的小图标