【问题标题】:Can't link GLFW3: undefined references无法链接 GLFW3:未定义的引用
【发布时间】:2014-05-06 21:54:39
【问题描述】:

我意识到以前有人问过类似的问题 (glfw3 compiling undefined references),但不幸的是我仍然无法让它工作。欢迎任何帮助!

下面是运行make时的编译器输出:

g++ -std=c++11 -Wall -Wextra -Werror -pedantic-errors -I/usr/local/include -c -o Main.o Main.cpp

g++ -std=c++11 -Wall -Wextra -Werror -pedantic-errors -I/usr/local/include -L/usr/local/lib -lglfw3 -lGL Main.o -o modernogl

Main.o:在函数“main”中:

Main.cpp:(.text+0x9): undefined reference to `glfwInit'

Main.cpp:(.text+0x3b): 对 `glfwCreateWindow' 的未定义引用

Main.cpp:(.text+0x4b): undefined reference to `glfwTerminate'

Main.cpp:(.text+0x5e): 对`glfwMakeContextCurrent'的未定义引用

Main.cpp:(.text+0x6c): 对 `glfwSwapBuffers' 的未定义引用

Main.cpp:(.text+0x71): 未定义对 `glfwPollEvents' 的引用

Main.cpp:(.text+0x7d): 对 `glfwWindowShouldClose' 的未定义引用

Main.cpp:(.text+0x92): undefined reference to `glfwDestroyWindow'

Main.cpp:(.text+0x97): 对 `glfwTerminate' 的未定义引用

collect2: 错误:ld 返回 1 个退出状态

make: *** [modernogl] 错误 1

这是 include 和 lib 目录在其中的内容:http://imgur.com/e6qXSjB,fASlBUm#1

以下是出处(不过应该没有问题……):

#include <GLFW/glfw3.h>

int main() {
    if (!glfwInit()) {
        return 1;
    }

    GLFWwindow* window {glfwCreateWindow(640, 480, "Modern OpenGL", nullptr, nullptr)};
    if (!window) {
        glfwTerminate();
        return 1;
    }

    glfwMakeContextCurrent(window);
    while (!glfwWindowShouldClose(window)) {
        glfwSwapBuffers(window);
        glfwPollEvents();
    }

    glfwDestroyWindow(window);
    glfwTerminate();
    return 0;
}

非常感谢您的帮助! - 埃里克

【问题讨论】:

    标签: c++ c++11 g++ undefined-reference glfw


    【解决方案1】:

    我只有库“libglfw3.a”的静态版本,我需要它的共享版本“libglfw.so”。确保使用 BUILD_SHARED_LIBS=ON 构建 GLFW3!

    【讨论】:

    • 只是为了说清楚:cmake -DCMAKE_INSTALL_PREFIX=/usr -DBUILD_SHARED_LIBS=ON .
    猜你喜欢
    • 2014-03-08
    • 2013-10-22
    • 2021-11-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-25
    • 1970-01-01
    • 2014-03-19
    相关资源
    最近更新 更多