vscode如何配置C/C++环境,支持函数跳转和自动补全
-
YUNTU所有的VSCODE工程编译都是基于CMake来实现的,所有可以很容易的被各个IDE/插件识别
VSCODE的C/C++插件可以用以下两种(任选其一即可),建议选择ClangDclangd 插件
安装
安装clangd,vscode会默认下载clangd-server,或者可以手动选择clangd的目录
配置
clangd的配置是每个workspace下的*.code-workspace文件里单独配置
{ "folders": [ { "path": "." } ], "settings": { "clangd.arguments": [ "--compile-commands-dir=${workspaceFolder}/build", "--query-driver=${env:APPDATA}/yt_config_tool/gcc-arm-none-eabi-10.3-2021.10/bin/arm-none-eabi-gcc.exe" ] } }
其中 --compile-commands-dir 是必须的,clangd会默认去搜索这个目录下的 compile_commands.json 文件,这个文件是工程经过cmake编译后产生的一个文件,
格式大概如下:{ "directory": "C:/Users/Frankie/Downloads/ha0_dd/build", "command": "C:\\Users\\Frankie\\AppData\\Roaming\\yt_config_tool\\gcc-arm-none-eabi-10.3-2021.10\\bin\\arm-none-eabi-gcc.exe -DARMCM7_DP -DCORTEXM -DCPU_YTM32B1HA0 -DYTM32B1HA0 -IC:/Users/Frankie/Downloads/ha0_dd/board -IC:/Users/Frankie/Downloads/ha0_dd/platform/drivers/src/clock/YTM32B1Hx -IC:/Users/Frankie/Downloads/ha0_dd/platform/drivers/src/pins -IC:/Users/Frankie/Downloads/ha0_dd/platform/drivers/inc -IC:/Users/Frankie/Downloads/ha0_dd/platform/devices/common -IC:/Users/Frankie/Downloads/ha0_dd/platform/devices -IC:/Users/Frankie/Downloads/ha0_dd/platform/devices/YTM32B1HA0/include -IC:/Users/Frankie/Downloads/ha0_dd/platform/devices/YTM32B1HA0/startup -IC:/Users/Frankie/Downloads/ha0_dd/CMSIS/Core/Include -IC:/Users/Frankie/Downloads/ha0_dd/rtos/osif -mcpu=cortex-m7 -g -mlittle-endian -mthumb -specs=nosys.specs -Wall -Werror=all -Wno-error=comment -g -O1 -ffunction-sections -fdata-sections -Wno-error=unused-variable -Wno-error=unused-parameter -Wno-error=unused-function -Wno-error=unused-but-set-variable -Wno-error=unused-result -Wno-error=maybe-uninitialized -Wno-error=sign-compare -Wno-error=strict-aliasing -Wno-error=unknown-pragmas -Wno-error=format -fdiagnostics-color=always -o CMakeFiles\\GENERATED_CONFIG_TARGET.dir\\board\\clock_config.c.o -c C:\\Users\\Frankie\\Downloads\\ha0_dd\\board\\clock_config.c", "file": "C:\\Users\\Frankie\\Downloads\\ha0_dd\\board\\clock_config.c", "output": "CMakeFiles\\GENERATED_CONFIG_TARGET.dir\\board\\clock_config.c.o" },
记录了每一个c文件的搜索路径,编写选项等信息。
--query-driver是可选测试,用于找到类似stdint.h 这种头文件,因为这些头文件在自己的工程下是不存在的。
配置好后,就可以进行跳转了。效果
数组自动加入索引
函数参数名的显示
代码自动补全
C/C++ 插件
因为这个插件不是很推荐,所以就简单解释一下安装
直接从vscode的扩展商店里安装即可
配置
c/c++的配置是每个workspace下的.vscode/c_cpp_properties.json文件里单独配置
{ "env": { "PROJ_DIR": "${workspaceFolder}" }, "configurations": [ { "name": "YTM32B1HA0", "intelliSenseMode": "gcc-x64", "includePath": [ "${PROJ_DIR}/board", "${PROJ_DIR}/platform/drivers/src/clock/YTM32B1Hx", "${PROJ_DIR}/platform/drivers/src/pins", "${PROJ_DIR}/platform/drivers/inc", "${PROJ_DIR}/platform/devices/common", "${PROJ_DIR}/platform/devices", "${PROJ_DIR}/platform/devices/YTM32B1HA0/include", "${PROJ_DIR}/platform/devices/YTM32B1HA0/startup", "${PROJ_DIR}/CMSIS/Core/Include", "${PROJ_DIR}/rtos/osif" ], "defines": [ "YTM32B1HA0", "CPU_YTM32B1HA0" ], "cStandard": "c11", "cppStandard": "c++17", "compileCommands": "${workspaceFolder}/build/compile_commands.json", "browse": { "path": [ "${workspaceFolder}" ], "limitSymbolsToIncludedHeaders": true, "databaseFilename": "" }, "configurationProvider": "ms-vscode.cmake-tools" } ] }
也可以指定 compile_commands.json 文件
帮助没办法联网的电脑使用YCT
帮助改进和优化YT CONFIG TOOL,有机会抽取YTM32B1ME0 EVB哦...