Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.6k views
in Technique[技术] by (71.8m points)

c++ - glfw Errors with glfwWindowHint

I have tried fallowing this tutorial and it did not work. I do not know why it is not working. I'm using Ubuntu 14.04 and GNU G++ command.

code:

#include <GLFW/glfw3.h>

int main(void) {
    glfwInit();
    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
    glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); 
    glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);

    glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);


    GLFWwindow* window = glfwCreateWindow(800, 600, "OpenGL", NULL, NULL);

    glfwMakeContextCurrent(window);

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

    glfwTerminate();
}

terminal:

command: g++ display.cpp -lglfw -o display.out
/tmp/cci33O9I.o: In function `main':
display.cpp:(.text+0x18): undefined reference to `glfwWindowHint'
display.cpp:(.text+0x27): undefined reference to `glfwWindowHint'
display.cpp:(.text+0x36): undefined reference to `glfwWindowHint'
display.cpp:(.text+0x45): undefined reference to `glfwWindowHint'
display.cpp:(.text+0x54): undefined reference to `glfwWindowHint'
display.cpp:(.text+0x73): undefined reference to `glfwCreateWindow'
display.cpp:(.text+0x83): undefined reference to `glfwMakeContextCurrent'
display.cpp:(.text+0xa2): undefined reference to `glfwWindowShouldClose'
collect2: error: ld returned 1 exit status
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You should not link to glfw, but link to glfw3. As here:

g++ display.cpp -lglfw3 -o display.out

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...