C++ glfw 错误:找不到“GLFW/glfw3.h”文件

时间:2021-07-23 11:04:24

标签: c++ visual-studio-code glfw

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

{
    "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

1 个答案:

答案 0 :(得分:2)

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