【问题标题】:cannot open source file "begin_code.h" (dependency of "SDL2/SDL.h")无法打开源文件“begin_code.h”(“SDL2/SDL.h”的依赖项)
【发布时间】:2021-01-19 02:23:39
【问题描述】:

在 Ubuntu 20.01 LTM 中尝试使用 VS Code 设置 SDL2 时,我收到以下 VS Code 错误:

cannot open source file "begin_code.h" (dependency of "SDL2/SDL.h")

有什么建议吗?

【问题讨论】:

    标签: gcc visual-studio-code sdl-2 ubuntu-20.04


    【解决方案1】:

    只需像这样将"/usr/include/SDL2/" 添加到您的 c_cpp_properties.json 中:

    {
        "configurations": [
            {
                "name": "Linux",
                "includePath": [
                    "${workspaceFolder}/**",
                    "/usr/include/SDL2/"
                ],
                "defines": [],
                "compilerPath": "/usr/bin/gcc",
                "cStandard": "gnu18",
                "cppStandard": "gnu++14",
                "intelliSenseMode": "gcc-x64"
            }
        ],
        "version": 4
    }
    

    【讨论】:

    【解决方案2】:

    如果你和我一样,在你的项目中没有c_cpp_properties.json 文件,你可以通过将以下行添加到你的settings.json 来解决它(在 VSCode 中,点击 Ctrl+ Shift+P 并搜索打开设置(JSON)):

    {
        // ...
        "C_Cpp.default.includePath": ["/usr/include/SDL2", "${default}"],
        //...
    }
    

    【讨论】:

      【解决方案3】:

      如果您的文件中没有“c_cpp_properties.json”文件 文件夹。

      与上述不同的答案,但我相信可能是更好的方法。

      在您的工作区创建 c_cpp_properties.json 执行以下操作:

      1. ctrl + shift + p(打开命令面板)
      2. 搜索“C/C++:编辑配置(JSON)”并点击
      3. “c_cpp_properties.json”文件将在您的工作区创建
      4. 将“/usr/include/SDL2/”添加到您的“c_cpp_properties.json”中,例如 https://stackoverflow.com/a/64187964/8540466
      5. 重新加载 C/C++ IntelliSense 扩展。

      我假设您已经有了扩展程序 《C/C++ IntelliSense、调试和代码浏览》 安装在你的 vscode 上。

      在这些步骤之后,我解决了这个问题。

      【讨论】:

        猜你喜欢
        • 2021-12-22
        • 1970-01-01
        • 1970-01-01
        • 2021-06-09
        • 1970-01-01
        • 1970-01-01
        • 2019-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多