Can't link GLFW3: undefined references

僤鯓⒐⒋嵵緔 提交于 2019-12-10 17:13:51

问题


I realize something similar has been asked before (glfw3 compiling undefined references), but I still can't get it to work unfortunately. Any help is welcome!

Below is the compiler output when running 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: In function `main':

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

Main.cpp:(.text+0x3b): undefined reference to `glfwCreateWindow'

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

Main.cpp:(.text+0x5e): undefined reference to `glfwMakeContextCurrent'

Main.cpp:(.text+0x6c): undefined reference to `glfwSwapBuffers'

Main.cpp:(.text+0x71): undefined reference to `glfwPollEvents'

Main.cpp:(.text+0x7d): undefined reference to `glfwWindowShouldClose'

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

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

collect2: error: ld returned 1 exit status

make: *** [modernogl] Error 1

Here is what the include and lib directories have inside them: http://imgur.com/e6qXSjB,fASlBUm#1

Below is the source (there shouldn't be any problem with it though...):

#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;
}

Thanks a lot for your help! - Erik


回答1:


I only had the static version of the library "libglfw3.a", I needed the shared version of it "libglfw.so". Make sure to build GLFW3 with BUILD_SHARED_LIBS=ON!



来源:https://stackoverflow.com/questions/22695857/cant-link-glfw3-undefined-references

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!