March 22, 2011

vertmont vertmont
Lab Rat
1 posts

Qt version of OpenGL SuperBible Triange - undefined reference GLBatch

 

I’m new to Qt and I’m trying to implement the examples in the OpenGL SuperBible which uses GLTools. I’m using Qt Creator (Qt Creator 2.0.94 (2.1.0-rc1)).
I expect that I’m missing something simple but I need some help.

Thanks for any help.

Dan
I run qmake and then Build Project.
I’m getting the following error from Build Project: Compile Output
These are all defined in GLTools.h and are in the gltools.lib

  1. g++ -enable-stdcall-fixup -Wl,-enable-auto-import -Wl,-enable-runtime-pseudo-reloc -mthreads -Wl -Wl,-subsystem,windows -o debug/SB_Triangle.exe debug/main.o debug/TriangleWidget.o debug/moc_TriangleWidget.o  -L'c:/Qt/2010.05/qt/lib' -lglu32 -lopengl32 -lgdi32 -luser32 -lmingw32 -lqtmaind "C:\Program Files\Microsoft SDKs\Windows\v7.1\Lib\glew32s.lib" "C:\Program Files\Microsoft SDKs\Windows\v7.1\Lib\gltools.lib" "C:\Program Files\Microsoft SDKs\Windows\v7.1\Lib\GlU32.Lib" -lQtOpenGLd4 -lQtGuid4 -lQtCored4
  2. debug/TriangleWidget.o: In function `TriangleWidget':
  3. *D:\Development\GPU\code\C++\Qt\OpenGL SuperBible\Triangle\SB_Triangle-build-desktop/../SB_Triangle/TriangleWidget.cpp:6: undefined reference to `GLBatch::GLBatch()'*

I’m using:

  • XP SP3
  • Qt Creator 2.0.94 (2.1.0-rc1)
  • Qt SDK – C:\Qt\2010.05

SB_Triangle.pro file

  1. QT       += core gui
  2. QT       += opengl
  3. TARGET = SB_Triangle
  4. TEMPLATE = app
  5. CONFIG += opengl glu glew gltools
  6.  
  7. INCLUDEPATH += .
  8. INCLUDEPATH += C:\Qt\2010.05\qt\include\Qt
  9. INCLUDEPATH += D:\Development\GPU\CppLibs\GLEW\glew-1.5.8\include
  10. INCLUDEPATH += D:\Development\GPU\CppLibs\GLTools\include
  11.  
  12. win32 : LIBS +=
  13. win32 : LIBS += $$quote(C:\Program Files\Microsoft SDKs\Windows\v7.1\Lib\glew32s.lib)
  14. win32 : LIBS += $$quote(C:\Program Files\Microsoft SDKs\Windows\v7.1\Lib\gltools.lib)
  15.  
  16. win32 : LIBS += $$quote(C:\Program Files\Microsoft SDKs\Windows\v7.1\Lib\GlU32.Lib)
  17.  
  18. SOURCES += main.cpp\
  19.         TriangleWidget.cpp
  20.  
  21. HEADERS  += TriangleWidget.h
  22.  
  23. FORMS    += TriangleWidget.ui

The error is on line 6, – ui(new Ui::TriangleWidget)
TriangleWidget.cpp

  1. #include "TriangleWidget.h"
  2. #include "ui_TriangleWidget.h"
  3.  
  4. TriangleWidget::TriangleWidget(QWidget *parent) :
  5.     QGLWidget(parent),
  6.     ui(new Ui::TriangleWidget)
  7. {
  8.     ui->setupUi(this);
  9. }
  10.  
  11. TriangleWidget::~TriangleWidget()
  12. {
  13.     delete ui;
  14. }
  15.  
  16. void TriangleWidget::ChangeSize(int w, int h)
  17. {
  18.   glViewport(0, 0, w, h);
  19. }
  20.  
  21. void TriangleWidget::SetupRC()
  22. {
  23.  // Blue background
  24.  glClearColor(0.0f, 0.0f, 1.0f, 1.0f );
  25.  shaderManager.InitializeStockShaders();
  26.  
  27.  // Load up a triangle
  28.  GLfloat vVerts[] = { -0.5f, 0.0f, 0.0f,
  29.             0.5f, 0.0f, 0.0f,
  30.             0.0f, 0.5f, 0.0f };
  31.  
  32.  triangleBatch.Begin(GL_TRIANGLES, 3);
  33.  triangleBatch.CopyVertexData3f(vVerts);
  34.  triangleBatch.End();
  35. }
  36.  
  37. void TriangleWidget::RenderScene(void)
  38. {
  39.  // Clear the window with current clearing color
  40.  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
  41.  
  42.  GLfloat vRed[] = { 1.0f, 0.0f, 0.0f, 1.0f };
  43.  shaderManager.UseStockShader(GLT_SHADER_IDENTITY, vRed);
  44.  triangleBatch.Draw();
  45.  
  46.  // Perform the buffer swap to display back buffer
  47.  //glutSwapBuffers();
  48.  swapBuffers();
  49.  
  50. }

TriangleWidget.h

  1. #ifndef TRIANGLEWIDGET_H
  2. #define TRIANGLEWIDGET_H
  3.  
  4. #include <GL/glew.h>
  5. #include <QGLWidget>
  6.  
  7. #include <GLTools.h>            // OpenGL toolkit
  8. #include <GLShaderManager.h>    // Shader Manager Class
  9.  
  10.  
  11. namespace Ui {
  12.   class TriangleWidget;
  13. }
  14.  
  15. // Based on Triangle.cpp in OpenGL SuperBible 5th edition
  16. // Port to Qt 4.7 - 3.20.2011 dpc
  17. // Our first OpenGL program that will just draw a triangle on the screen.
  18.  
  19. class TriangleWidget : public QGLWidget
  20. {
  21.   Q_OBJECT
  22.  
  23. public:
  24.   explicit TriangleWidget(QWidget *parent = 0);
  25.   ~TriangleWidget();
  26.  
  27. protected:
  28.   ///////////////////////////////////////////////////////////////////////////////
  29.   // Window has changed size, or has just been created. In either case, we need
  30.   // to use the window dimensions to set the viewport and the projection matrix.
  31.   void ChangeSize(int w, int h);
  32.  
  33.   ///////////////////////////////////////////////////////////////////////////////
  34.   // This function does any needed initialization on the rendering context.
  35.   // This is the first opportunity to do any OpenGL related tasks.
  36.   void SetupRC();
  37.  
  38.   ///////////////////////////////////////////////////////////////////////////////
  39.   // Called to draw scene
  40.   void RenderScene(void);
  41.  
  42. private:
  43.   Ui::TriangleWidget *ui;
  44.   GLBatch triangleBatch;
  45.   GLShaderManager shaderManager;
  46. };
  47.  
  48. #endif // TRIANGLEWIDGET_H

1 reply

March 23, 2011

Bradley Bradley
Lab Rat
300 posts

Looks like you are building with MinGW GCC, but trying to link with Microsoft Visual C++ libraries. The two compilers are not compatible and libraries built with one cannot be mixed with the other.

 Signature 

Nokia Certified Qt Specialist.

 
  ‹‹ installation and getting started with first app      Compiled application don’t find QML elements ››

You must log in to post a reply. Not a member yet? Register here!