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

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Windows 10-OpenGL的故障排除代码(带有GLFW):无效的参数相关的知识,希望对你有一定的参考价值。

因此,我认为是时候学习如何在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中添加链接器选项对我来说要容易得多,因此...

答案

参数中的空格很重要!

另一答案

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

以上是关于Windows 10-OpenGL的故障排除代码(带有GLFW):无效的参数的主要内容,如果未能解决你的问题,请参考以下文章

如何在 Windows 上对 PHPMailer/OpenSSL TLS SMTP 进行故障排除?

双系统引导故障排除

使用 Linux for Windows 子系统对 ssh“连接超时”进行故障排除

Windows 7 用户文件夹迁移故障排除一例

在Windows中使用NPM和node-gyp进行故障排除

使用 Anaconda Python 的 PyQt Windows 安装程序 - 未找到 PyQt4;如何进行故障排除?