笔记-vscode下的c_cpp_properties.json文件配置,兼容visual studio
这篇笔记的目的就是配置好c/c++插件代码的智能提示,方便以后写嵌入式代码的时候能够快速配置好
例子(来自官方文档)
{
"env": {
"myDefaultIncludePath": ["${workspaceFolder}", "${workspaceFolder}/include"],
"myCompilerPath": "/usr/local/bin/gcc-7"
},
"configurations": [
{
"name": "Mac",
"intelliSenseMode": "clang-x64",
"includePath": ["${myDefaultIncludePath}", "/another/path"],
"macFrameworkPath": ["/System/Library/Frameworks"],
"defines": ["FOO", "BAR=100"],
"forcedInclude": ["${workspaceFolder}/include/config.h"],
"compilerPath": "/usr/bin/clang",
"cStandard": "c11",
"cppStandard": "c++17",
"compileCommands": "/path/to/compile_commands.json",
"browse": {
"path": ["${workspaceFolder}"],
"limitSymbolsToIncludedHeaders": true,
"databaseFilename": ""
}
}
],
"version": 4
}
vscode的目的是为了代码的智能提示,并不是要实时检测代码的正确性,所以不必要将在编译时加上的宏定义在这里写上,用browse来自动搜索可用的宏定义就行了
cStandard
用于智能感知的C语言标准版本,根据实际情况确定
cppStandard
用于智能感知的c++语言标准的版本,根据实际情况确定
configurationProvider
用不到
compileCommands
The full path to the compile_commands.json file for the workspace. The include paths and defines discovered in this file will be used instead of the values set for includePath and defines settings. If the compile commands database does not contain an entry for the translation unit that corresponds to the file you opened in the editor, then a warning message will appear and the extension will use the includePath and defines settings instead.
用不到,因为有browse
browse(重要)
The set of properties used when “C_Cpp.intelliSenseEngine” is set to “Tag Parser” (also referred to as “fuzzy” IntelliSense, or the “browse” engine). These properties are also used by the Go To Definition/Declaration features, or when the “Default” IntelliSense engine is unable to resolve the #includes in your source files(官方文档)
如果只是将需要包含的头文件放在includePath字段中,那么include的问题解决了,但是defines的问题还没有解决,这将会出现一大堆的提示,这些提示大部分都是因为缺少相应的宏定义引起的,而browse可以搜索相应browse.path字段中所有的宏定义,并把缺少的宏定义补全,让Definition/Declaration操作可以无障碍
browse字段
很少,只有三个
path
A list of paths for the Tag Parser to search for headers included by your source files. If omitted, includePath will be used as the path. Searching on these paths is recursive by default. Specify * to indicate non-recursive search. For example: /usr/include will search through all subdirectories while /usr/include/* will not(官方文档)
注意通配符问题,与includePath字段不相同
limitSymbolsToIncludedHeaders
When true, the Tag Parser will only parse code files that have been directly or indirectly included by a source file in ${workspaceFolder}. When false, the Tag Parser will parse all code files found in the paths specified in the browse.path list.(官方文档)
通常设置为true,如果有些代码没法智能提示可以将该字段设置为false试试
databaseFilename
用不上
实例
这是我现在在使用的配置文件
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**",
"/root/esp8266_3.2/ESP8266_RTOS_SDK-3.2/**"
],
"defines": [],
"compilerPath": "/root/esp8266/xtensa-lx106-elf/bin/xtensa-lx106-elf-gcc",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "gcc-x64",
"browse": {
"path": [
"${workspaceFolder}",
"/root/esp8266_3.2/ESP8266_RTOS_SDK-3.2"
],
"limitSymbolsToIncludedHeaders": true
}
}
],
"version": 4
}
再一次说明 : 仅仅是为了代码提示,至于提示的质量不做任何保证