Question

Im having an issue using GLUT with monodevelop. Im using the following code:

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <GL/glew.h>
#include <GL/freeglut.h>
#include <GL/freeglut_ext.h>
#include <GL/freeglut_std.h>
#include <GL/gl.h>
#define WINDOW_TITLE_PREFIX "Chapter 1"

int CurrentWidth = 800,
    CurrentHeight = 600,
    WindowHandle = 0;

void Initialize(int, char*[]);
void InitWindow(int, char*[]);
void ResizeFunction(int, int);
void RenderFunction(void);

int main(int argc, char* argv[])
{
    Initialize(argc, argv);

    glutMainLoop();

    exit(EXIT_SUCCESS);
}

void Initialize(int argc, char* argv[])
{
    InitWindow(argc, argv);

    fprintf(
        stdout,
        "INFO: OpenGL Version: %s\n",
        glGetString(GL_VERSION)
    );

    glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
}

void InitWindow(int argc, char* argv[])
{
    glutInit(&argc, argv);

    glutInitContextVersion(4, 0);
    glutInitContextFlags(GLUT_FORWARD_COMPATIBLE);
    glutInitContextProfile(GLUT_CORE_PROFILE);

    glutSetOption(
        GLUT_ACTION_ON_WINDOW_CLOSE,
        GLUT_ACTION_GLUTMAINLOOP_RETURNS
    );

    glutInitWindowSize(CurrentWidth, CurrentHeight);

    glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);

    WindowHandle = glutCreateWindow(WINDOW_TITLE_PREFIX);

    if(WindowHandle < 1) {
        fprintf(
            stderr,
            "ERROR: Could not create a new rendering window.\n"
        );
        exit(EXIT_FAILURE);
    }

    glutReshapeFunc(ResizeFunction);
    glutDisplayFunc(RenderFunction);
}

void ResizeFunction(int Width, int Height)
{
    CurrentWidth = Width;
    CurrentHeight = Height;
    glViewport(0, 0, CurrentWidth, CurrentHeight);
}

void RenderFunction(void)
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glutSwapBuffers();
    glutPostRedisplay();
}

and im getting the following errors:

g++ -o "/home/mark/Projects/GlutTest/GlutTest/bin/Debug/GlutTest" "/home/mark/Projects/GlutTest/GlutTest/bin/Debug/main.o"  
/home/mark/Projects/GlutTest/GlutTest/bin/Debug/main.o: In function `main':
/home/mark/Projects/GlutTest/GlutTest/main.c:24: undefined reference to `glutMainLoop'
/home/mark/Projects/GlutTest/GlutTest/bin/Debug/main.o: In function `Initialize(int, char**)':
/home/mark/Projects/GlutTest/GlutTest/main.c:37: undefined reference to `glGetString'
/home/mark/Projects/GlutTest/GlutTest/main.c:39: undefined reference to `glClearColor'
/home/mark/Projects/GlutTest/GlutTest/bin/Debug/main.o: In function `InitWindow(int, char**)':
/home/mark/Projects/GlutTest/GlutTest/main.c:44: undefined reference to `glutInit'
/home/mark/Projects/GlutTest/GlutTest/main.c:46: undefined reference to `glutInitContextVersion'
/home/mark/Projects/GlutTest/GlutTest/main.c:47: undefined reference to `glutInitContextFlags'
/home/mark/Projects/GlutTest/GlutTest/main.c:48: undefined reference to `glutInitContextProfile'
/home/mark/Projects/GlutTest/GlutTest/main.c:53: undefined reference to `glutSetOption'
/home/mark/Projects/GlutTest/GlutTest/main.c:55: undefined reference to `glutInitWindowSize'
/home/mark/Projects/GlutTest/GlutTest/main.c:57: undefined reference to `glutInitDisplayMode'
/home/mark/Projects/GlutTest/GlutTest/main.c:59: undefined reference to `glutCreateWindow'
/home/mark/Projects/GlutTest/GlutTest/main.c:69: undefined reference to `glutReshapeFunc'
/home/mark/Projects/GlutTest/GlutTest/main.c:70: undefined reference to `glutDisplayFunc'
/home/mark/Projects/GlutTest/GlutTest/bin/Debug/main.o: In function `ResizeFunction(int, int)':
/home/mark/Projects/GlutTest/GlutTest/main.c:77: undefined reference to `glViewport'
/home/mark/Projects/GlutTest/GlutTest/bin/Debug/main.o: In function `RenderFunction()':
/home/mark/Projects/GlutTest/GlutTest/main.c:82: undefined reference to `glClear'
/home/mark/Projects/GlutTest/GlutTest/main.c:84: undefined reference to `glutSwapBuffers'
/home/mark/Projects/GlutTest/GlutTest/main.c:85: undefined reference to `glutPostRedisplay'
collect2: ld returned 1 exit status

I have freeglut.h and glew.h in the project directory and im getting those errors. Im not sure what im missing but it has to be something simple.

Was it helpful?

Solution

You forgot to link in the GLUT libraries…perhaps you want to try some of these: -lglut -lGLU -lGL

And likely some of these: -lXmu -lXi -lXext -lX11 -lm

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top