3

http://programanddesign.com/cpp/qt-opengl-code-example/

I am trying out above example and included

#include <GL/glu.h>
#include <GL/glut.h>

as well. but I am getting a gluOrtho2D undefined error. what am I doing wrong here ?

genpfault
  • 51,148
  • 11
  • 85
  • 139
Tharanga
  • 2,007
  • 4
  • 32
  • 50

4 Answers4

4

You need to put the OpenGL and GLU libraries in your object, the '#include' directive is not an library, it's just a reference of what the library can do for you. Libraries have the .so extension on linux, .dylib on MacOS and .dll / .lib on windows, you need to tell us What you are using to compile, ( MinGW, VisualStudip, QtCreator ) and also tell us what libraries are you linking with. for OpenGL, in linux is -lGL, in windows is -lOpenGL32.

Nicol Bolas
  • 449,505
  • 63
  • 781
  • 982
Tomaz Canabrava
  • 2,320
  • 15
  • 20
  • Thank you very much for the response. I am compiling with QtCreator in Linux. Using free glut. I do not think I am using -lGL option when adding it in the make did not help me. but I found that it works just fine with glOrtho – Tharanga Feb 17 '12 at 14:09
3

When you have a "undefined reference" you have to check if you have linked your libraries!

Compile with "-l" flag or, if you use -for instance- eclipse go to: project->propreties->C++Build->Settings->GCC C++ Linker->Libraries and add your library!

Luca Davanzo
  • 21,000
  • 15
  • 120
  • 146
2

Include all these libraries: Example: Here new2.cpp is main c++ file and Output.out is an executable file that is created by compiling the new2.cpp file in g++ compiler. And I had also included the libraries with -I and linked them with -l. At last I have executed the result by doing ./Output.out

mandeep@mandeep-HP:~/Desktop$ g++ new2.cpp -o Output.out -I/usr/include/GL -I/usr/lib -lGL -lglut -lGLU mandeep@mandeep-HP:~/Desktop$ ./Output.out

0

Follow these two steps if you are using windows.

  1. Add #include <QtOpenGL> to your .h file of the class.
  2. Add QT += opengl in your .pro file.
meghaljani
  • 61
  • 9