OpenGL 项目返回时带有未定义的引用



我正在从这个网站学习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 GLFWn" );
        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 GLEWn");
        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:UsersjaredDocumentsNetBeansProjectsopengl_1/main.cpp:21: undefined reference to `glfwInit'
C:UsersjaredDocumentsNetBeansProjectsopengl_1/main.cpp:27: undefined reference to `glfwOpenWindowHint'
C:UsersjaredDocumentsNetBeansProjectsopengl_1/main.cpp:28: undefined reference to `glfwOpenWindowHint'
C:UsersjaredDocumentsNetBeansProjectsopengl_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:UsersjaredDocumentsNetBeansProjectsopengl_1/main.cpp:30: undefined reference to `glfwOpenWindowHint'
make[2]: Leaving directory `/cygdrive/c/Users/jared/Documents/NetBeansProjects/opengl_1'
C:UsersjaredDocumentsNetBeansProjectsopengl_1/main.cpp:31: undefined reference to `glfwOpenWindowHint'
nbproject/Makefile-Debug.mk:59: recipe for target `.build-conf' failed
C:UsersjaredDocumentsNetBeansProjectsopengl_1/main.cpp:34: undefined reference to `glfwOpenWindow'
make[1]: Leaving directory `/cygdrive/c/Users/jared/Documents/NetBeansProjects/opengl_1'
C:UsersjaredDocumentsNetBeansProjectsopengl_1/main.cpp:37: undefined reference to `glfwTerminate'
C:UsersjaredDocumentsNetBeansProjectsopengl_1/main.cpp:42: undefined reference to `_imp__glewInit@0'
C:UsersjaredDocumentsNetBeansProjectsopengl_1/main.cpp:47: undefined reference to `glfwSetWindowTitle'
C:UsersjaredDocumentsNetBeansProjectsopengl_1/main.cpp:50: undefined reference to `glfwEnable'
C:UsersjaredDocumentsNetBeansProjectsopengl_1/main.cpp:53: undefined reference to `glClearColor@16'
C:UsersjaredDocumentsNetBeansProjectsopengl_1/main.cpp:59: undefined reference to `glfwSwapBuffers'
C:UsersjaredDocumentsNetBeansProjectsopengl_1/main.cpp:62: undefined reference to `glfwGetKey'
C:UsersjaredDocumentsNetBeansProjectsopengl_1/main.cpp:63: undefined reference to `glfwGetWindowParam'
C:UsersjaredDocumentsNetBeansProjectsopengl_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。

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

最新更新