链接 GLFW 文件时出错

Errors during linking GLFW files

我已经从源代码构建了 GLFW,并尝试在 Ubuntu Linux 上使用它构建应用程序。但是,g++ 总是抛出关于未定义引用的错误。我关注了很多网站和帖子,但它们并没有解决我的问题。这是我的代码:

#include <stdio.h>
#include <stdlib.h>
#include <GL/glew.h>
#include <GLFW/glfw3.h>
#include <glm/glm.hpp>

using namespace glm;

int main() {
    glfwWindowHint(GLFW_SAMPLES, 4);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
    glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
    glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);

    GLFWwindow* window;
    window = glfwCreateWindow( 1024, 768, "Tutorial 01", NULL, NULL);
    if( window == NULL ){
        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;
    }
    glfwMakeContextCurrent(window);
    glewExperimental=true;
    if (glewInit() != GLEW_OK) {
        fprintf(stderr, "Failed to initialize GLEW\n");
        return -1;
    }
    return 0;
}

我正在用这个命令编译这个程序:g++ glfw_prog.cpp -lGL -lglfw3 -o glfw_prog

但是,我收到这么长的错误 https://pastebin.com/1b8fB2h7

如何解决这个问题?

我让你的程序在 Ubuntu 上使用以下标志进行编译:

g++ glfw_prog.cpp -lGL -lglfw -lGLEW -o glfw_prog

我关注了 this 网站并解决了我的问题。我不得不使用命令 gcc -o glfw_prog glfw_prog.cpp $(pkg-config --static --libs glfw3) -lGLEW。我只需要添加额外的 -lGLEW 标志以及 pkg-config 搜索路径。

更具体地说,这是完整且独立于系统的命令:
gcc -o glfw_prog glfw_prog.cpp -L/usr/local/lib -lglfw3 -lrt -lm -ldl -lX11 -lpthread -lxcb -lXau -lXdmcp -lGLEW -lGL