PDA

View Full Version : Buid error: collect2.exe: error: ld returned 1 exit status



Demonlaplce
21st April 2016, 09:43
Im new on Qt5.6, im following the tutorial on youtube to run my project qt+opengl, but when I use the glClearColor and glClear functions, it shows this error, can someone help me to solve it?

pro file
#-------------------------------------------------
#
# Project created by QtCreator 2016-04-20T15:40:00
#
#-------------------------------------------------

QT += core gui opengl

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = opengl_test
TEMPLATE = app


SOURCES += main.cpp\
mainwindow.cpp \
glwidget.cpp

HEADERS += mainwindow.h \
glwidget.h

FORMS += mainwindow.ui

glwidget.h file
#ifndef GLWIDGET_H
#define GLWIDGET_H

#include <QGLWidget>
class GLWidget : public QGLWidget
{
Q_OBJECT
public:
explicit GLWidget(QWidget *parent = 0);
void initializeGL();
void paintGL();
void resizeGL(int w, int h);

};

#endif // GLWIDGET_H

glwidget.cpp file
#include "glwidget.h"

GLWidget::GLWidget(QWidget *parent):
QGLWidget(parent)
{


}

void GLWidget::initializeGL(){
glClearColor(1, 1, 0, 1);
}

void GLWidget::paintGL(){
glClear(GL_COLOR_BUFFER_BIT);
}
void GLWidget::resizeGL(int w, int h){

}

And here are my errors:
debug/glwidget.o: In function `ZN8GLWidget12initializeGLEv':
C:\Users\xingchen ming\Documents\build-opengl_test-Desktop_Qt_5_6_0_MinGW_32bit-Debug/../opengl_test/glwidget.cpp:11: undefined reference to `_imp__glClearColor@16'
debug/glwidget.o: In function `ZN8GLWidget7paintGLEv':
C:\Users\xingchen ming\Documents\build-opengl_test-Desktop_Qt_5_6_0_MinGW_32bit-Debug/../opengl_test/glwidget.cpp:15: undefined reference to `_imp__glClear@4'
collect2.exe: error: ld returned 1 exit status
Makefile.Debug:71: recipe for target 'debug\opengl_test.exe' failed
mingw32-make[1]: *** [debug\opengl_test.exe] Error 1

thx for your attention

Added after 24 minutes:

Problem solved.