简体   繁体   中英

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. 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> . 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:

 :-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. The error occurs whatever I put the -lglut32 in the qmake file or not.

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. The compiler just cannot locate the lib file correctly. 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? Thank you guys whoever gives any suggestions!

Alright guys, the question has been solved by just adding #include <QOpenGLWidget> to my xh :)

It seems that we do not need other application framework like GLUT for QT project.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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