Monodevelop和GLUT问题

时间:2012-01-10 23:25:20

标签: c monodevelop glut freeglut glew

我在使用GLUT和monodevelop时遇到了问题。我使用以下代码:

#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();
}

我发现以下错误:

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

我在项目目录中有freeglut.h和glew.h并且我得到了这些错误。我不确定我缺少什么,但它必须是简单的。

1 个答案:

答案 0 :(得分:1)

你忘了链接GLUT库...也许你想尝试其中一些:-lglut -lGLU -lGL

可能还有其中一些:-lXmu -lXi -lXext -lX11 -lm