title: Problems with OpenGL when running QT Creator
body: <p>I am trying to run basic examples of OpenGL using QT Creator to give color to a window. However, I am getting error in the compilation when calling the OpenGL instruction:
  glClearColor(1.0,1.0,0.0,1.0);
  The *.pro file is the next:</p>
  
  <pre><code>QT       += core gui opengl
  greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
  TARGET = test2
  TEMPLATE = app
  SOURCES += main.cpp\
          mainwindow.cpp \
      glwidget.cpp
  HEADERS  += mainwindow.h \
      glwidget.h
  FORMS    += mainwindow.ui
  </code></pre>
  
  <p>The glwidget.h is the next:</p>
  
  <pre><code>#ifndef GLWIDGET_H
  #define GLWIDGET_H
  #include &lt;QGLWidget&gt;
  class GLWidget : public QGLWidget
  {
      Q_OBJECT
  public:
      explicit GLWidget(QWidget *parent = 0);
      void initializeGL();    
  };
  #endif // GLWIDGET_H
  </code></pre>
  
  <p>The glwidget.cpp is the next:</p>
  
  <pre><code>#include "glwidget.h"
  GLWidget::GLWidget(QWidget *parent) :
      QGLWidget(parent)
  {
  }
  void GLWidget::initializeGL(){
      glClearColor(1.0,1.0,0.0,1.0);
  }
  </code></pre>
  
  <p>The main.cpp:</p>
  
  <pre><code>#include "mainwindow.h"
  #include &lt;QApplication&gt;
  int main(int argc, char *argv[])
  {
      QApplication a(argc, argv);
      MainWindow w;
      w.show();
      return a.exec();
  }
  </code></pre>
  
  <p>I have checked that in the *.pro I have included opengl:
  QT       += core gui opengl
  In addition, I have deleted the "YourProjectName-build-desktop" folder created by QT Creator and build again without success.</p>
  
  <p>The error is:
  C:\test2\glwidget.cpp:9: error: undefined reference to `_imp__glClearColor@16'
  where line 9 is glClearColor(1.0,1.0,0.0,1.0);</p>
  
  <p>Which extra step I am missing?</p>
  
  <p>Thank you in advance for your help</p>
  
  <p>Cheers
  © 2016 Microsoft Terms Privacy &amp; cookies Developers English (United States)</p>