简体   繁体   English

我在QT中使用opengl32,但是当我包含glut.h时,发生链接错误

[英]I am using opengl32 in QT, but when I include glut.h, a link error occurs

FORMS    += mainwindow.ui
LIBS += -lopengl32 -lglut32 //(error is here, the second term)


win32:CONFIG(release, debug|release): LIBS += -LC:/ (path to some lib) -l(a good lib that is not regarding to this question)
else:win32:CONFIG(debug, debug|release): LIBS += -LC:/ (path to some lib) -l(a lib)
INCLUDEPATH += C:/(path to some directory)
DEPENDPATH += C:/(path to some directory)

It works fine when I just use -lopengl32 and connect my openGLWidget to my mainWindow, which means I can use all the functions from opengl library. 当我只使用-lopengl32并将openGLWidget连接到mainWindow时,它可以很好地工作,这意味着我可以使用opengl库中的所有功能。 But now I need to use a function for another h file (name it xh here) created outside of my openglwidget.h, so I just simply inlcude <GL/glut.h> . 但是现在我需要对在openglwidget.h之外创建的另一个h文件(在此处命名为xh)使用一个函数,所以我只需要添加<GL/glut.h> It seems that QT can locate the glut.h file before I compile the whole project, in other words, the purple color of key word 'GLfloat' indicates glut.h is successfully called in my xh However, when I compile the project, a link problem occurs: 看来QT可以在编译整个项目之前找到glut.h文件,换句话说,关键字'GLfloat'的紫色表示xh已成功调用glut.h。但是,当我编译项目时,发生链接问题:

 :-1: error: LNK1181: cannot open input file 'glut32.lib'

I don't think I need specify the detailed path for my glut32.lib, because it is right there in my visual studio's library path. 我认为不需要为glut32.lib指定详细路径,因为它在我的Visual Studio的库路径中。 The error occurs whatever I put the -lglut32 in the qmake file or not. 无论我是否将-lglut32放在qmake文件中,都会发生该错误。

Also, not just for glut32.lib, say I have another y.lib that can be run in my visual studio 2015 without any error, but still the same problem occurs when I use this y.lib in my QT project. 另外,不仅对于glut32.lib,还说我还有另一个y.lib可以在我的visual studio 2015中运行而没有任何错误,但是当我在QT项目中使用此y.lib时,仍然会出现相同的问题。 The compiler just cannot locate the lib file correctly. 编译器只是无法正确找到lib文件。 The error was right same to this one I post above. 错误与我上面发布的错误相同。

So my question can be simplified as: how should I use openGL library when it is not a widget class of the mainWindow in the QT? 因此,我的问题可以简化为:当openGL库不是QT中mainWindow的小部件类时,应如何使用? Thank you guys whoever gives any suggestions! 谢谢大家提供的任何建议!

Alright guys, the question has been solved by just adding #include <QOpenGLWidget> to my xh :) 好的,您只需在我的xh中添加#include <QOpenGLWidget>即可解决此问题:

It seems that we do not need other application framework like GLUT for QT project. 看来我们不需要QT项目的其他应用程序框架(例如GLUT)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM