undefined ref to glutLeaveMainLoop

Hi all,
I have a big problem (well, for me, it’s big, but I am sure it’s nothing for you!).

I am using freeglut, and the magic glutLeaveMainLoop function.

Freeglut is installed and working. I have no problem using freeglut, except when I try to glutLeaveMainLoop. It says ‘undefined reference to ‘glutLeaveMainLoop’’. I have been trying for hours to figure out why, but I can’t!

I have tried replacing freeglut by openglut (no, I didn’t forget to change the includes!), and nothing!

I would be very grateful if someone can help me!!!

Here is my code:

 

#include <GL/freeglut_std.h>
#include <GL/freeglut_ext.h>
#include <stdlib.h>

void quad()
{
        glBegin(GL_QUADS);
                glVertex2f( 0.0f, 1.0f);  // Top Left
                glVertex2f( 1.0f, 1.0f);  // Top Right
                glVertex2f( 1.0f, 0.0f);  // Bottom Right
                glVertex2f( 0.0f, 0.0f);  // Bottom Left
        glEnd();
}

void draw()
{
        // Make background colour black
        glClearColor( 0, 0, 0, 0 );
        glClear ( GL_COLOR_BUFFER_BIT );
        
        // Push the matrix stack - more on this later
        glPushMatrix();

        // Set drawing colour to blue
        glColor3f( 0, 0, 1 );
        
        // Move the shape to middle of the window
        // More on this later
        glTranslatef(-0.5, -0.5, 0.0);
        
        // Call our Quad Method
        quad();

        // Pop the Matrix
        glPopMatrix();
        
        // display it 
        glutSwapBuffers();
}

// Keyboard method to allow ESC key to quit
void keyboard(unsigned char key,int x,int y)
{
        if(key==27){
	 glutLeaveMainLoop();
	 }
}


int main(int argc, char **argv)
{
        // Double Buffered RGB display 
        glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE);
        // Set window size
        glutInitWindowSize( 500,500 );
        glutCreateWindow("Test");
        // Declare the display and keyboard functions
        glutDisplayFunc(draw);
        glutKeyboardFunc(keyboard);
        // Start the Main Loop
        glutMainLoop();
}
 

Hi,

I’ve never seen that function before, cool!

A little searching reveals that older versions of GLUT, even free and open did not support this.

Since you don’t do anything after you leave the main loop, you might consider just calling exit().

-Rawk

Yes, I have the same issue as you encounter, has anyone given an efficient solution to this problem? or give a solution to quit glut process without exit the programme

Check to see that you’re using FreeGLUT instead of GLUT (they’re not the same thing) and a version of it that is recent enough to have that function. And make sure that you’re actually linking to FreeGLUT rather than GLUT.

Or switch to a more functional toolset.

Use a modern version of GLUT. The original SGI GLUT doesn’t provide any mechanism to terminate the event loop. Using setjmp/longjmp (or threads, or similar) might work, or it might result in weird bugs.