1

我刚刚完成了为 C++ 安装 GLFW 以使用 OpenGL,当我运行以下代码时:

#include <stdlib.h>
#include <GL/glfw.h>

int main(int argc, char *argv[])
{
    int running = GL_TRUE;

    if (!glfwInit())
        exit(EXIT_FAILURE);

    if (!glfwOpenWindow(300, 300, 0, 0, 0, 0, 0, 0, GLFW_WINDOW))
    {
        glfwTerminate();
        exit(EXIT_FAILURE);
    }

    while (running)
    {
        glClear(GL_COLOR_BUFFER_BIT);
        glClearColor(rand() % 255 + 1, rand() % 255 + 1, rand() % 255 + 1, 0);

        glfwSwapBuffers();

        running = !glfwGetKey(GLFW_KEY_ESC) && glfwGetWindowParam(GLFW_OPENED);
    }

    glfwTerminate();

    exit(EXIT_SUCCESS);
}

,它会引发以下错误:

Error:
build/Debug/MinGW-Windows/main.o: In function `main':
C:\Users\User\Dropbox\NetBeans Workspace\OpenGL_Testing/main.cpp:8: undefined reference to `glfwInit'
C:\Users\User\Dropbox\NetBeans Workspace\OpenGL_Testing/main.cpp:11: undefined reference to `glfwOpenWindow'
C:\Users\User\Dropbox\NetBeans Workspace\OpenGL_Testing/main.cpp:13: undefined reference to `glfwTerminate'
C:\Users\User\Dropbox\NetBeans Workspace\OpenGL_Testing/main.cpp:22: undefined reference to `glfwSwapBuffers'
C:\Users\User\Dropbox\NetBeans Workspace\OpenGL_Testing/main.cpp:24: undefined reference to `glfwGetKey'
C:\Users\User\Dropbox\NetBeans Workspace\OpenGL_Testing/main.cpp:24: undefined reference to `glfwGetWindowParam'
C:\Users\User\Dropbox\NetBeans Workspace\OpenGL_Testing/main.cpp:27: undefined reference to `glfwTerminate'

是的,我已将 opengl32.lib 链接到我的项目中。

4

0 回答 0