【问题标题】:Errors during linking GLFW files链接 GLFW 文件时出错
【发布时间】:2020-10-18 12:05:00
【问题描述】:

我已经从源代码构建了 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

如何解决这个问题?

【问题讨论】:

  • 请不要使用错误消息的屏幕截图。相反,使用正确的格式(作为代码)粘贴错误消息。另请参阅How to Ask
  • 我提供的链接不是任何截图。这是一个显示错误的文本。我无法在此处粘贴它,因为它超过了字数限制。
  • 哦,对不起,这不是截图。尽管如此,错误消息仍应直接粘贴到问题帖子中。如果您的日志太长,则只显示第一条错误消息,或几条第一条消息。如果您认为完整的日志也有用,您也可以提供它的链接。

标签: c++ linux opengl g++


【解决方案1】:

我已关注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

【讨论】:

    【解决方案2】:

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

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

    【讨论】:

    • 我有glfw3 而不是glfw。当我使用开关-lGLEW 时,出现此错误:/usr/bin/ld: /usr/local/lib/libglfw3.a(vulkan.c.o): undefined reference to symbol 'dlclose@@GLIBC_2.2.5' /usr/bin/ld: /lib/x86_64-linux-gnu/libdl.so.2: error adding symbols: DSO missing from command line collect2: error: ld returned 1 exit status
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-03-27
    • 1970-01-01
    • 2018-06-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多