当试图在Ubuntu 20.01 LTM中使用VS代码设置SDL2时,我得到以下VS代码错误:
cannot open source file "begin_code.h" (dependency of "SDL2/SDL.h")
有什么建议吗?
只需将"/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
}
以防您没有;c_cpp_properties.json";文件文件夹
与上面的答案不同,但我相信这可能是一个更好的方法。
在您的工作区上创建c_cpp_properties.json执行以下操作:
- ctrl+shift+p(打开命令调色板(
- 搜索";C/C++:编辑配置(JSON(";然后点击它
- "c_cpp_properties.json";文件将在您的工作区中创建
- 添加"/usr/include/SDL2/";到您的";c_cpp_properties.json";喜欢https://stackoverflow.com/a/64187964/8540466
- 重新加载C/C++IntelliSense扩展
我想你已经有了扩展名"C/C++IntelliSense、调试和代码浏览";安装在您的vscode上。
经过这些步骤,这个问题为我解决了。
如果你和我一样,在你的项目中没有c_cpp_properties.json
文件,你可以通过在settings.json
中添加以下行来解决它(在VSCode中,点击Ctrl+Shift+p并搜索Open settings(JSON((:
{
// ...
"C_Cpp.default.includePath": ["/usr/include/SDL2", "${default}"],
//...
}