【问题标题】:How to run and compile C++ GLFW code using Atom with the package gpp-compiler如何使用 Atom 和 gpp-compiler 包运行和编译 C++ GLFW 代码
【发布时间】:2018-09-27 15:16:14
【问题描述】:

所以我想在学习 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 库文件。

谢谢你的回答: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

【问题讨论】:

    标签: c++ mingw atom-editor glfw


    【解决方案1】:

    所以我已经让它工作了,所以我所做的只是编译程序而不链接 GLFW 库。因为我在 atom 中使用 MinGW 作为我的 C++ 编译器,所以我需要将它添加到 gpp-compiler packages settings C++ Compiler Options -lglfw3dll -lopengl32 并将 glfw3.dll 文件放在与 main.cpp 文件相同的文件夹中,然后它就可以工作了.请注意,您必须将 GLFW 的 lib 文件放到 MinGW libs 文件夹中,并将 GLFW 头文件添加到 MinGW 的 include 文件夹中

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-01-29
      • 2022-01-18
      • 2020-02-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多