4
votes

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

1 Answers

4
votes

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!