首页 > 解决方案 > glfw3.dll 运行代码时未发现系统错误

问题描述

我在 Visual Studio Code(代码编辑器,而不是 IDE)中设置了 GLFW。当我运行代码时,它给了我一个系统错误:- glfw3.dll not found。

这是我从 GLFW 文档中复制的代码:

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

        /* Swap front and back buffers */
        glfwSwapBuffers(window);

        /* Poll for and process events */
        glfwPollEvents();
    }

    glfwTerminate();
    return 0;
}

这是我的 tasks.json 文件:-

    {
    "version": "2.0.0",
    "tasks": [
        {
            "type": "cppbuild",
            "label": "C/C++: cl.exe build active file",
            "command": "cl.exe",
            "args": [
                "/Zi",
                "/EHsc",
                "/nologo",
                "/I${workspaceFolder}\\glfw\\include",
                "/Fe:",
                "${fileDirname}\\${fileBasenameNoExtension}.exe",
                "${workspaceFolder}\\*.cpp",

                "opengl32.lib",
                "${workspaceFolder}\\glfw\\lib-vc2019\\glfw3dll.lib"

            ],
            "options": {
                "cwd": "${workspaceFolder}"
            },
            "problemMatcher": [
                "$msCompile"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "detail": "compiler: cl.exe"
        }
    ]
}

这是一个屏幕截图: 在此处输入图像描述

标签: c++openglvisual-studio-codec++17glfw

解决方案


推荐阅读