vscode GLFW/GLAD 拒绝编译

vscode GLFW/GLAD refusing to compile

提问人:Mason Cooreman 提问时间:11/7/2023 最后编辑:Mason Cooreman 更新时间:11/7/2023 访问量:55

问:

我正在尝试获得运行 opengl 程序的环境,我遵循了以下教程: https://medium.com/@vivekjha92/setup-opengl-with-vs-code-82852c653c43 据我所知,我已经正确地完成了所有操作,但是当我点击运行按钮时,编译器说有一堆未定义的引用,谁能帮我运行它?

tasks.json文件:

{
  "tasks": [
      {
          "type": "cppbuild",
          "label": "C/C++: g++.exe build active file",
          "command": "C:\\MinGW\\bin\\g++.exe",          
          "args": [
            "-g",
            "-std=c++17",
            "-I${workspaceFolder}/include",
            "-L${workspaceFolder}/lib",
            "${workspaceFolder}/src/\\*.cpp",
            "${workspaceFolder}/src/glad.c",
            "-o",
            "${fileDirname}\\${fileBasenameNoExtension}.exe",
            "-lglfw3dll"
        ],
          "options": {
              "cwd": "${fileDirname}"
          },
          "problemMatcher": [
              "$gcc"
          ],
          "group": {
              "kind": "build",
              "isDefault": true
          },
          "detail": "Task generated by Debugger."
      }
  ],
  "version": "2.0.0"
}

launch.json文件:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "C/C++: g++.exe build and debug active file",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceFolder}/myprogram.exe",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${fileDirname}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "miDebuggerPath": "C:\\MinGW\\bin\\gdb.exe",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                },
                {
                    "description": "Set Disassembly Flavor to Intel",
                    "text": "-gdb-set disassembly-flavor intel",
                    "ignoreFailures": true
                }
            ],
            "preLaunchTask": "C/C++: g++.exe build active file"
        }
    ]
}

错误:

C:\Users\176542\AppData\Local\Temp\ccl505PU.o: In function `main':
C:/Users/176542/Desktop/Physics_OpenGL/src/main.cpp:17: undefined reference to `glfwInit'
C:/Users/176542/Desktop/Physics_OpenGL/src/main.cpp:18: undefined reference to `glfwWindowHint'
C:/Users/176542/Desktop/Physics_OpenGL/src/main.cpp:19: undefined reference to `glfwWindowHint'
C:/Users/176542/Desktop/Physics_OpenGL/src/main.cpp:20: undefined reference to `glfwWindowHint'
C:/Users/176542/Desktop/Physics_OpenGL/src/main.cpp:28: undefined reference to `glfwCreateWindow'
C:/Users/176542/Desktop/Physics_OpenGL/src/main.cpp:32: undefined reference to `glfwTerminate'
C:/Users/176542/Desktop/Physics_OpenGL/src/main.cpp:35: undefined reference to `glfwMakeContextCurrent'
C:/Users/176542/Desktop/Physics_OpenGL/src/main.cpp:36: undefined reference to `glfwSetFramebufferSizeCallback'
C:/Users/176542/Desktop/Physics_OpenGL/src/main.cpp:40: undefined reference to `glfwGetProcAddress'
C:/Users/176542/Desktop/Physics_OpenGL/src/main.cpp:48: undefined reference to `glfwWindowShouldClose'
C:/Users/176542/Desktop/Physics_OpenGL/src/main.cpp:61: undefined reference to `glfwSwapBuffers'
C:/Users/176542/Desktop/Physics_OpenGL/src/main.cpp:62: undefined reference to `glfwPollEvents'
C:/Users/176542/Desktop/Physics_OpenGL/src/main.cpp:67: undefined reference to `glfwTerminate'
C:\Users\176542\AppData\Local\Temp\ccl505PU.o: In function `Z12processInputP10GLFWwindow':
C:/Users/176542/Desktop/Physics_OpenGL/src/main.cpp:75: undefined reference to `glfwGetKey'
C:/Users/176542/Desktop/Physics_OpenGL/src/main.cpp:76: undefined reference to `glfwSetWindowShouldClose'
collect2.exe: error: ld returned 1 exit status
C++ visual-studio-code opengl glfw glad

评论

0赞 Jesper Juhl 11/7/2023
我建议使用比过于复杂的 VSCode 更简单的东西。也许是像 Visual Studio Community Edition、QtCreator 这样的 IDE,或者只是一个简单的编辑器,如 vi、Emacs 或记事本。
0赞 Mason Cooreman 11/7/2023
@JesperJuhl我不能,vscode 是我学校计算机上唯一允许的东西
0赞 Jesper Juhl 11/7/2023
@MasonCooreman“我不能”——如果你愿意,你当然可以。“我学校电脑上唯一允许的东西”——糟糕的学校;打破规则,无论如何都要使用更好的东西。
0赞 Mason Cooreman 11/7/2023
@JesperJuhl Visual Studio 几乎不可能下载,但我的学校 IT 部门甚至试图帮助我做到这一点。这是一个地区的事情,我准备通过拥有 vscode 来打破规则。我尝试侧载 ubuntuu,但他们锁定了 bios。
2赞 Ripi2 11/7/2023
对于 g++ 编译器,而不是尝试使用 .并确保 glfw 库是使用与项目相同的目标(32/64 位)编译的。-lglfw3dll-lglfw3

答: 暂无答案