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 的新手(抱歉)。
原文由 Diego Trazzi 发布,翻译遵循 CC BY-SA 4.0 许可协议
这就是我在 Mac(MacBook Pro 2015,macOS Catalina)上的 VS Code 中使用 clang 包含 OpenGL“GLWF”和“glad”库的方式。而且我有智能感知,可以构建和调试。
include/glad/glad.h
- 要包含的库文件src/helloworld.cpp - 主文件
.vscode/c_cpp_properties.json
.vscode/launch.json
.vscode/tasks.json (您需要包含实现文件
include/glad.c
,不仅是标题)