如何使用带有包gpp-compiler的Atom运行和编译C ++ GLFW代码

时间:2018-09-27 15:16:14

标签: c++ mingw atom-editor glfw

因此,在学习GLFW的过程中,我想使用Atom作为我的IDE。这是我的代码

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

        glBegin(GL_TRIANGLES);
        glVertex2f(-0.5f, -0.5f);
        glVertex2f(0.0f, 0.5f);
        glVertex2f(0.5f, -0.5f);
        glEnd();

        /* Swap front and back buffers */
        glfwSwapBuffers(window);
        /* Poll for and process events */
        glfwPollEvents();
    }

    glfwTerminate();
    return 0;
}

因此,我已经尝试过搜索与我的问题类似的问题,但是幸运的是,这些问题的答案不起作用。我已经将GLFW的lib文件添加到MinGW lib文件夹中,但它不起作用,这是我得到的错误。我知道我收到此错误,因为gpp编译器找不到GLFW lib文件。

谢谢您回答:D

C:\Users\Asus\AppData\Local\Temp\cc4lMOFw.o:main.cpp:(.text+0x17): undefined reference to `glfwInit'
C:\Users\Asus\AppData\Local\Temp\cc4lMOFw.o:main.cpp:(.text+0x56): undefined reference to `glfwCreateWindow'
C:\Users\Asus\AppData\Local\Temp\cc4lMOFw.o:main.cpp:(.text+0x64): undefined reference to `glfwTerminate'
C:\Users\Asus\AppData\Local\Temp\cc4lMOFw.o:main.cpp:(.text+0x79): undefined reference to `glfwMakeContextCurrent'
C:\Users\Asus\AppData\Local\Temp\cc4lMOFw.o:main.cpp:(.text+0x84): undefined reference to `glfwWindowShouldClose'
C:\Users\Asus\AppData\Local\Temp\cc4lMOFw.o:main.cpp:(.text+0x9d): undefined reference to `_imp__glClear@4'
C:\Users\Asus\AppData\Local\Temp\cc4lMOFw.o:main.cpp:(.text+0xae): undefined reference to `_imp__glBegin@4'
C:\Users\Asus\AppData\Local\Temp\cc4lMOFw.o:main.cpp:(.text+0xcb): undefined reference to `_imp__glVertex2f@8'
C:\Users\Asus\AppData\Local\Temp\cc4lMOFw.o:main.cpp:(.text+0xe4): undefined reference to `_imp__glVertex2f@8'
C:\Users\Asus\AppData\Local\Temp\cc4lMOFw.o:main.cpp:(.text+0x101): undefined reference to `_imp__glVertex2f@8'
C:\Users\Asus\AppData\Local\Temp\cc4lMOFw.o:main.cpp:(.text+0x10b): undefined reference to `_imp__glEnd@0'
C:\Users\Asus\AppData\Local\Temp\cc4lMOFw.o:main.cpp:(.text+0x118): undefined reference to `glfwSwapBuffers'
C:\Users\Asus\AppData\Local\Temp\cc4lMOFw.o:main.cpp:(.text+0x11d): undefined reference to `glfwPollEvents'
C:\Users\Asus\AppData\Local\Temp\cc4lMOFw.o:main.cpp:(.text+0x127): undefined reference to `glfwTerminate'
collect2.exe: error: ld returned 1 exit status

1 个答案:

答案 0 :(得分:0)

所以我已经开始工作了,所以我在做的只是编译程序而没有链接GLFW库。因为我在Atom中将MinGW用作我的C ++编译器,所以需要将其添加到gpp-compiler软件包设置C ++编译器选项-lglfw3dll -lopengl32并将glfw3.dll文件与main.cpp文件放在同一文件夹中,然后它可以工作。请注意,您必须将GLFW的lib文件放入MinGW的libs文件夹,并将GLFW头文件添加到MinGW的include文件夹