g ++不与GLFW链接

时间:2020-07-08 11:33:41

标签: c++ g++ glfw

我正在尝试使用g ++从glfw页面编译示例程序。

#include <GLFW/glfw3.h>

int main(void)
{
    GLFWwindow* window;

    /* Initialize the library */
    if (!glfwInit())
        return -1;

    /* Create a windowed mode window and its OpenGL context */
    window = glfwCreateWindow(640, 480, "Hello World", NULL, NULL);
    if (!window)
    {
        glfwTerminate();
        return -1;
    }

    /* Make the window's context current */
    glfwMakeContextCurrent(window);

    /* Loop until the user closes the window */
    while (!glfwWindowShouldClose(window))
    {
        /* Render here */
        glClear(GL_COLOR_BUFFER_BIT);

        /* Swap front and back buffers */
        glfwSwapBuffers(window);

        /* Poll for and process events */
        glfwPollEvents();
    }

    glfwTerminate();
    return 0;
}

问题是我得到了对glfw函数的未定义引用。 g ++命令:

g++ -IGLFW/include -c sample.cpp
g++ -o sample.exe -LGLFW/lib-mingw-w64 sample.o libglfw3.a

错误消息:

c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: sample.o:sample.cpp:(.text+0x17): undefined reference to `glfwInit'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: sample.o:sample.cpp:(.text+0x6a): undefined reference to `glfwCreateWindow'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: sample.o:sample.cpp:(.text+0x78): undefined reference to `glfwTerminate'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: sample.o:sample.cpp:(.text+0x8d): undefined reference to `glfwMakeContextCurrent'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: sample.o:sample.cpp:(.text+0x98): undefined reference to `glfwWindowShouldClose'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: sample.o:sample.cpp:(.text+0xb1): undefined reference to `_imp__glClear@4'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: sample.o:sample.cpp:(.text+0xc2): undefined reference to `_imp__glBegin@4'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: sample.o:sample.cpp:(.text+0xdf): undefined reference to `_imp__glVertex2f@8'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: sample.o:sample.cpp:(.text+0xf8): undefined reference to `_imp__glVertex2f@8'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: sample.o:sample.cpp:(.text+0x115): undefined reference to `_imp__glVertex2f@8'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: sample.o:sample.cpp:(.text+0x11f): undefined reference to `_imp__glEnd@0'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: sample.o:sample.cpp:(.text+0x12c): undefined reference to `glfwSwapBuffers'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: sample.o:sample.cpp:(.text+0x131): undefined reference to `glfwPollEvents'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: sample.o:sample.cpp:(.text+0x13b): undefined reference to `glfwTerminate'
collect2.exe: error: ld returned 1 exit status

我已经检查了多个来源,看看我是否链接错误,但对我来说一切看起来都正确。

我的操作系统是Windows 10

0 个答案:

没有答案