-   Programming (
-   -   Compiling errors when compiling OpenGL with GLUT (

Hvl 06-28-2011 06:36 AM

Compiling errors when compiling OpenGL with GLUT

I have just started to look at OpenGL, and I got the book "OpenGL Superbible 5th edition" by Richard. S. Wright, jr and others.

The code in the book makes use of various libs', for example GLUT, GLEW and a GLTools (Which is made by the books authors I think).

The problem is that when I compile the code from the first example application I get this error:

[hakon@hakon-laptop opengl-superbible]$g++ triangle.cpp -o triangle
/tmp/cctwzBOq.o: In function `ChangeSize(int, int)':
triangle.cpp:(.text+0x23): undefined reference to `glViewport'
/tmp/cctwzBOq.o: In function `SetupRC()':
triangle.cpp:(.text+0x48): undefined reference to `glClearColor'
triangle.cpp:(.text+0x52): undefined reference to `GLShaderManager::InitializeStockShaders()'
triangle.cpp:(.text+0xb3): undefined reference to `GLBatch::Begin(unsigned int, unsigned int, unsigned int)'
triangle.cpp:(.text+0xce): undefined reference to `GLBatch::End()'
/tmp/cctwzBOq.o: In function `RenderScene()':
triangle.cpp:(.text+0xe2): undefined reference to `glClear'
triangle.cpp:(.text+0x11d): undefined reference to `GLShaderManager::UseStockShader(GLT_STOCK_SHADER, ...)'
triangle.cpp:(.text+0x127): undefined reference to `GLBatch::Draw()'
triangle.cpp:(.text+0x12c): undefined reference to `glutSwapBuffers'
/tmp/cctwzBOq.o: In function `main':
triangle.cpp:(.text+0x14c): undefined reference to `gltSetWorkingDirectory(char const*)'
triangle.cpp:(.text+0x15f): undefined reference to `glutInit'
triangle.cpp:(.text+0x169): undefined reference to `glutInitDisplayMode'
triangle.cpp:(.text+0x178): undefined reference to `glutInitWindowSize'
triangle.cpp:(.text+0x182): undefined reference to `glutCreateWindow'
triangle.cpp:(.text+0x18c): undefined reference to `glutReshapeFunc'
triangle.cpp:(.text+0x196): undefined reference to `glutDisplayFunc'
triangle.cpp:(.text+0x19b): undefined reference to `glewInit'
triangle.cpp:(.text+0x1ae): undefined reference to `glewGetErrorString'
triangle.cpp:(.text+0x1d6): undefined reference to `glutMainLoop'
/tmp/cctwzBOq.o: In function `__static_initialization_and_destruction_0(int, int)':
triangle.cpp:(.text+0x204): undefined reference to `GLBatch::GLBatch()'
triangle.cpp:(.text+0x209): undefined reference to `GLBatch::~GLBatch()'
triangle.cpp:(.text+0x225): undefined reference to `GLShaderManager::GLShaderManager()'
triangle.cpp:(.text+0x22a): undefined reference to `GLShaderManager::~GLShaderManager()'
/tmp/cctwzBOq.o: In function `GLBatch::CopyVertexData3f(float*)':
triangle.cpp:(.text._ZN7GLBatch16CopyVertexData3fEPf[GLBatch::CopyVertexData3f(float*)]+0x1f): undefined reference to `GLBatch::CopyVertexData3f(float (*) [3])'
collect2: ld returned 1 exit status
Also when running a pre-built example of the same source I am experiencing some problems:

[hakon@hakon-laptop downloads]$./Triangle
freeglut (./Triangle): ERROR: Internal error <FBConfig with necessary capabilities not found> in function fgOpenWindow
X Error of failed request: BadWindow (invalid Window parameter)
Major opcode of failed request: 4 (X_DestroyWindow)
Resource id in failed request: 0x0
Serial number of failed request: 30
Current serial number in output stream: 33
Segmentation fault
I am running Crunchbang Linux Statler 64-bit, based on Debian. I have installed the correct nVidia Drivers for my GeForce 9600M GS card. I also have the following packages installed:
- libgl1-nvidia-legacy-96xx-glx(Also the -dev package)
- nvidia-legacy-96xx (Also -dev)
- nvidia-glx-dev
- libglew1.5 (Also -dev)
- libglut3 (Also -dev)
- freeglut3 (Also -dev)

As far as I understand, the freeglut3 packages should replace the libglut3, so I first tried without libglut3, but with the same result. I am also able to run other OpenGL applications like Tremulous and Minecraft.

Some other information:

[hakon@hakon-laptop ~]$uname -r
[hakon@hakon-laptop ~]$g++ --ver
Using built-in specs.
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Debian 4.4.5-8' --with-bugurl=file:///usr/share/doc/gcc-4.4/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.4 --enable-shared --enable-multiarch --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.4 --libdir=/usr/lib --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug --enable-objc-gc --with-arch-32=i586 --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 4.4.5 (Debian 4.4.5-8)
Source code from the book:

// Triangle.cpp
// Our first OpenGL program that will just draw a triangle on the screen.

#include <GLTools.h>            // OpenGL toolkit
#include <GLShaderManager.h>    // Shader Manager Class

#ifdef __APPLE__
#include <glut/glut.h>          // OS X version of GLUT
#include <GL/glut.h>            // Windows FreeGlut equivalent

GLBatch        triangleBatch;
GLShaderManager        shaderManager;

// Window has changed size, or has just been created. In either case, we need
// to use the window dimensions to set the viewport and the projection matrix.
void ChangeSize(int w, int h)
        glViewport(0, 0, w, h);

// This function does any needed initialization on the rendering context.
// This is the first opportunity to do any OpenGL related tasks.
void SetupRC()
        // Blue background
        glClearColor(0.0f, 0.0f, 1.0f, 1.0f );

        // Load up a triangle
        GLfloat vVerts[] = { -0.5f, 0.0f, 0.0f,
                                  0.5f, 0.0f, 0.0f,
                                                  0.0f, 0.5f, 0.0f };

        triangleBatch.Begin(GL_TRIANGLES, 3);

// Called to draw scene
void RenderScene(void)
        // Clear the window with current clearing color

        GLfloat vRed[] = { 1.0f, 0.0f, 0.0f, 1.0f };
        shaderManager.UseStockShader(GLT_SHADER_IDENTITY, vRed);

        // Perform the buffer swap to display back buffer

// Main entry point for GLUT based programs
int main(int argc, char* argv[])
        glutInit(&argc, argv);
        glutInitWindowSize(800, 600);

        GLenum err = glewInit();
        if (GLEW_OK != err) {
                fprintf(stderr, "GLEW Error: %s\n", glewGetErrorString(err));
                return 1;

        return 0;

I guess it's ok to post it here, it's freely available for download on the homepage for the book.

So, anyone having any ideas on what to do? :)

H_TeXMeX_H 06-28-2011 07:50 AM

Why are you using the legacy drivers, why not the latest ones ?

16pide 06-28-2011 08:10 AM

I had same error on my fedora machine

undefined reference to `glViewport'
I installed glut dev environment:

yum install freeglut-devel
in your debian based machine it will be slightly different, but you get the idea.
I also added -lglut as an option to g++

g++ -lglut triangle.cpp -o triangle
Anyway, now the error is gone.

Hvl 06-28-2011 08:21 AM


Originally Posted by H_TeXMeX_H (Post 4397919)
Why are you using the legacy drivers, why not the latest ones ?

Mhm, I think I must have enabled it when I was searching around and trying different packages to solve this problem. Back on the newest drivers now.

Quakeboy02: I allerady have the freeglut-dev packages installed, so I don't think thats the problem.

All times are GMT -5. The time now is 07:52 AM.