【问题标题】:glfw Errors with glfwWindowHintglfw 错误与 glfwWindowHint
【发布时间】:2014-07-18 03:46:47
【问题描述】:

我已经尝试过闲置this 教程,但没有奏效。我不知道为什么它不起作用。我正在使用 Ubuntu 14.04 和 GNU G++ 命令。

代码:

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

终端:

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

【问题讨论】:

    标签: c++ linux g++ glfw


    【解决方案1】:

    您不应链接到glfw,而应链接到glfw3。如这里:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-03-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多