OpenGL项目返回未定义的引用

时间:2012-10-10 02:45:13

标签: c++ windows opengl

我正在关注这个site的OpenGL教程。我已经下载并安装(希望正确)使用的OpenGL库。 (GLEW,GLFW,GLM)。但是,当我从站点编译代码时,我发现很多错误与未定义的引用。

代码:

#include <stdio.h>
#include <stdlib.h>

#include <GL/glew.h>

#include <GL/glfw.h>

#include <glm/glm.hpp>
using namespace glm;

int main( void )
{
    // Initialize GLFW
    if( !glfwInit() )
    {
        fprintf( stderr, "Failed to initialize GLFW\n" );
        return -1;
    }

    glfwOpenWindowHint(GLFW_FSAA_SAMPLES, 4);
    glfwOpenWindowHint(GLFW_WINDOW_NO_RESIZE,GL_TRUE);
    glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 3);
    glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 3);
    glfwOpenWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);

    // Open a window and create its OpenGL context
    if( !glfwOpenWindow( 1024, 768, 0,0,0,0, 32,0, GLFW_WINDOW ) )
    {
        fprintf( stderr, "Failed to open GLFW window. If you have an Intel GPU, they are not 3.3 compatible. Try the 2.1 version of the tutorials.\n" );
        glfwTerminate();
        return -1;
    }

    // Initialize GLEW
    if (glewInit() != GLEW_OK) {
        fprintf(stderr, "Failed to initialize GLEW\n");
        return -1;
    }

    glfwSetWindowTitle( "Playground" );

    // Ensure we can capture the escape key being pressed below
    glfwEnable( GLFW_STICKY_KEYS );

    // Dark blue background
    glClearColor(0.0f, 0.0f, 0.3f, 0.0f);

    do{
        // Draw nothing, see you in tutorial 2 !

        // Swap buffers
        glfwSwapBuffers();

    } // Check if the ESC key was pressed or the window was closed
    while( glfwGetKey( GLFW_KEY_ESC ) != GLFW_PRESS &&
           glfwGetWindowParam( GLFW_OPENED ) );

    // Close OpenGL window and terminate GLFW
    glfwTerminate();

    return 0;
}

错误:

"make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
make[1]: Entering directory `/cygdrive/c/Users/jared/Documents/NetBeansProjects/opengl_1'
"make"  -f nbproject/Makefile-Debug.mk dist/Debug/MinGW-Windows/opengl_1.exe
make[2]: Entering directory `/cygdrive/c/Users/jared/Documents/NetBeansProjects/opengl_1'
mkdir -p dist/Debug/MinGW-Windows
g++.exe     -o dist/Debug/MinGW-Windows/opengl_1 build/Debug/MinGW-Windows/main.o  
build/Debug/MinGW-Windows/main.o: In function `main':
C:\Users\jared\Documents\NetBeansProjects\opengl_1/main.cpp:21: undefined reference to `glfwInit'
C:\Users\jared\Documents\NetBeansProjects\opengl_1/main.cpp:27: undefined reference to `glfwOpenWindowHint'
C:\Users\jared\Documents\NetBeansProjects\opengl_1/main.cpp:28: undefined reference to `glfwOpenWindowHint'
C:\Users\jared\Documents\NetBeansProjects\opengl_1/main.cpp:29: undefined reference to `glfwOpenWindowHint'
nbproject/Makefile-Debug.mk:62: recipe for target `dist/Debug/MinGW-Windows/opengl_1.exe' failed
C:\Users\jared\Documents\NetBeansProjects\opengl_1/main.cpp:30: undefined reference to `glfwOpenWindowHint'
make[2]: Leaving directory `/cygdrive/c/Users/jared/Documents/NetBeansProjects/opengl_1'
C:\Users\jared\Documents\NetBeansProjects\opengl_1/main.cpp:31: undefined reference to `glfwOpenWindowHint'
nbproject/Makefile-Debug.mk:59: recipe for target `.build-conf' failed
C:\Users\jared\Documents\NetBeansProjects\opengl_1/main.cpp:34: undefined reference to `glfwOpenWindow'
make[1]: Leaving directory `/cygdrive/c/Users/jared/Documents/NetBeansProjects/opengl_1'
C:\Users\jared\Documents\NetBeansProjects\opengl_1/main.cpp:37: undefined reference to `glfwTerminate'
C:\Users\jared\Documents\NetBeansProjects\opengl_1/main.cpp:42: undefined reference to `_imp__glewInit@0'
C:\Users\jared\Documents\NetBeansProjects\opengl_1/main.cpp:47: undefined reference to `glfwSetWindowTitle'
C:\Users\jared\Documents\NetBeansProjects\opengl_1/main.cpp:50: undefined reference to `glfwEnable'
C:\Users\jared\Documents\NetBeansProjects\opengl_1/main.cpp:53: undefined reference to `glClearColor@16'
C:\Users\jared\Documents\NetBeansProjects\opengl_1/main.cpp:59: undefined reference to `glfwSwapBuffers'
C:\Users\jared\Documents\NetBeansProjects\opengl_1/main.cpp:62: undefined reference to `glfwGetKey'
C:\Users\jared\Documents\NetBeansProjects\opengl_1/main.cpp:63: undefined reference to `glfwGetWindowParam'
C:\Users\jared\Documents\NetBeansProjects\opengl_1/main.cpp:66: undefined reference to `glfwTerminate'
collect2: ld returned 1 exit status
make[2]: *** [dist/Debug/MinGW-Windows/opengl_1.exe] Error 1
make[1]: *** [.build-conf] Error 2
make: *** [.build-impl] Error 2


BUILD FAILED (exit value 2, total time: 875ms)

注意:我使用Netbeans(带有C ++插件)作为IDE。

1 个答案:

答案 0 :(得分:2)

重新读取makefile输出,我发现你实际上并没有链接GL库。您需要修改项目设置以包含库。

相关问题