C++ glfw Error: 'GLFW/glfw3.h' file not found

C++ glfw Error: 'GLFW/glfw3.h' file not found

我是 Vulkan 的新手,正在尝试重新创建网页上的教程向我展示的内容,我正在使用 VS Code,并且在尝试编译时出现错误,它表明 GLFW/glfw3.h即使我将它包含在 c_cpp_properties.json.

中的 includePath 项目中,也没有找到
{
    "configurations": [
        {
            "name": "Win32",
            "includePath": [
                "${workspaceFolder}/**",
                "${workspaceFolder}/src/**",
                "${workspaceFolder}/lib/**",
                "${workspaceFolder}/include/**",
                "${workspaceFolder}/lib/glfw/lib-mingw-w64/**",
                "C:/VulkanSDK/1.2.182.0/Lib/**",
                "C:/VulkanSDK/1.2.182.0/Include/**",
                "C:/Users/___/scoop/apps/llvm/current/lib/clang/12.0.1/include/**"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "_UNICODE"
            ],
            "compilerPath": "C:/Users/___/scoop/shims/clang++.exe",
            "cStandard": "c17",
            "cppStandard": "c++17",
            "intelliSenseMode": "windows-clang-x64",
            "macFrameworkPath": [],
            "forcedInclude": [
                "${workspaceFolder}/include/GLFW/glfw3.h"
            ]
        }
    ],
    "version": 4
}

main.cpp

// Code from the tutorial
#define GLFW_INCLUDE_VULKAN
#include <GLFW/glfw3.h>

#define GLM_FORCE_RADIANS
#define GLM_FORCE_DEPTH_ZERO_TO_ONE
#include <glm/vec4.hpp>
#include <glm/mat4x4.hpp>

#include <iostream>

int main() {
    glfwInit();

    glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
    GLFWwindow* window = glfwCreateWindow(800, 600, "Vulkan window", nullptr, nullptr);

    uint32_t extensionCount = 0;
    vkEnumerateInstanceExtensionProperties(nullptr, &extensionCount, nullptr);

    std::cout << extensionCount << " extensions supported\n";

    glm::mat4 matrix;
    glm::vec4 vec;
    auto test = matrix * vec;

    while(!glfwWindowShouldClose(window)) {
        glfwPollEvents();
    }

    glfwDestroyWindow(window);

    glfwTerminate();

    return 0;
}

我已经仔细检查了文件路径以确保它是正确的,但错误仍然出现,我也尝试了 #include <vulkan/vulkan.h> 而不是 #define GLFW_INCLUDE_VULKAN,结果显示 'vulkan/vulkan.h' file not found

你所做的 c_cpp_properties.json 仅适用于 IDE / intellisense。您还必须在 tasks.json 中将包含路径传递给编译器,因为编译器也需要了解它们。