【发布时间】:2022-01-15 03:20:43
【问题描述】:
IntelliSense 使用 c_cpp_properties.json >> includePath 来查找自动完成的标头,但我注意到我仍然需要在 task.json >> tasks >> args 中指定包含路径来构建。
我在文档中发现 includePath 与我在“-I”中指定的路径几乎相同:
您为此设置指定的路径与您指定的路径相同 您将通过 -I 开关发送到您的编译器。当你的来源 文件被解析后,IntelliSense 引擎会将这些路径添加到 #include 指令指定的文件,同时尝试 解决它们。不会递归搜索这些路径。*
- 我是否通过在构建任务的 args 中指定所有库和包含目录来正确设置 VSCode?还是应该以不同的方式完成?
- 谁能解释一下 includePath 和 browse 之间的区别?解释链接对我来说并不完全清楚
这是我的 c_cpp_properties.json 的示例:
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**",
"D:/github/dependencies/SDL2-2.0.8/include"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"compilerPath": "C:\\Program Files\\mingw-w64\\x86_64-8.1.0-posix-seh-rt_v6-rev0\\mingw64\\bin\\g++.exe",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "clang-x64",
"browse": {
"path": [
"${workspaceFolder}/**"
]
}
}
],
"version": 4
}
和task.json:
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "build",
"type": "shell",
"command": "g++",
"args": [
"-g",
"main2.cpp",
"-ID:\\github\\dependencies\\SDL2-2.0.8\\include",
"-LD:\\github\\dependencies\\SDL2-2.0.8\\lib\\x64",
"-lSDL2main","-lSDL2", "-lopengl32",
"-o",
"test-sdl"
]
}
],
"group": {
"kind": "build",
"isDefault": true
},
"problemMatcher":"$gcc"
}
是一个简单的问题,但我是 VSCode 的新手(抱歉)。
【问题讨论】:
-
我有同样的情况,问同样的问题。如果你找到了解释,请分享,谢谢:)
-
这能回答你的问题吗? #include errors detected in vscode
标签: c++ build visual-studio-code g++