Windows 10-OpenGL的故障排除代码(带有GLFW):无效的参数

问题描述 投票:0回答:2

因此,我认为是时候学习如何在C ++中使用OpenGL了。我无法使用最简单的代码。

我通常使用原子,但是在cmd中添加链接器选项对我来说要容易得多,因此代码就从那里开始(同样,如果将链接器选项添加到atom中的编译器选项中,输出是相同的。)>

我已经尝试编译了2天,但我不知道自己缺少什么。请帮助我:(

我是C ++新手,所以请记住这一点。

项目源代码(来自GLFW网站):

#include <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;
}

编译器:

g++ (MinGW.org GCC Build-20200227-1) 9.2.0

我尝试过的命令和错误:

1。

    g++ -I <pathHeaderFolder> Application.cpp -Wl, -BStatic -L <pathLibraryFolder> -lglu32 -lopengl32 -lkernel32 -luser32 -lgdi32 -lws2_32
    c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: cannot find : Invalid argument
    collect2.exe: error: ld returned 1 exit status

2。

    g++ Application.cpp -I <pathHeaderFolder>
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\Bruh\AppData\Local\Temp\cctDJEee.o:Application.cpp:(.text+0x17): undefined reference to `glfwInit'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\Bruh\AppData\Local\Temp\cctDJEee.o:Application.cpp:(.text+0x56): undefined reference to `glfwCreateWindow'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\Bruh\AppData\Local\Temp\cctDJEee.o:Application.cpp:(.text+0x64): undefined reference to `glfwTerminate'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\Bruh\AppData\Local\Temp\cctDJEee.o:Application.cpp:(.text+0x76): undefined reference to `glfwMakeContextCurrent'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\Bruh\AppData\Local\Temp\cctDJEee.o:Application.cpp:(.text+0x81): undefined reference to `glfwWindowShouldClose'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\Bruh\AppData\Local\Temp\cctDJEee.o:Application.cpp:(.text+0x96): undefined reference to `_imp__glClear@4'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\Bruh\AppData\Local\Temp\cctDJEee.o:Application.cpp:(.text+0xa6): undefined reference to `glfwSwapBuffers'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\Bruh\AppData\Local\Temp\cctDJEee.o:Application.cpp:(.text+0xab): undefined reference to `glfwPollEvents'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\Bruh\AppData\Local\Temp\cctDJEee.o:Application.cpp:(.text+0xb2): undefined reference to `glfwTerminate'
collect2.exe: error: ld returned 1 exit status

3。

g++ Application.cpp -I <pathHeaderFolder> -Wl, -BStatic -<pathLibraryFolder>\libglfw3.a 
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: cannot find : Invalid argument
collect2.exe: error: ld returned 1 exit status

4。

g++ -I <pathHeaderFolder> Application.cpp -Wl, -BStatic -L <pathLibraryFolder> -libglfw3.a
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: cannot find : Invalid argument
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: cannot find -libglfw3.a
collect2.exe: error: ld returned 1 exit status

5。

g++ -I <pathHeaderFolder> Application.cpp -Wl, -BStatic -L <pathLibraryFolder>libglfw3.a -mwindows
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: cannot find : Invalid argument
collect2.exe: error: ld returned 1 exit status

因此,我认为是时候学习如何在C ++中使用OpenGL了。我无法使用最简单的代码。我通常使用原子,但是在cmd中添加链接器选项对我来说要容易得多,因此...

c++ opengl gcc glfw
2个回答
1
投票

参数中的空格很重要!


0
投票

[确定,我尝试删除空间,但不能解决问题。我遇到错误:

© www.soinside.com 2019 - 2024. All rights reserved.