Vscode环境配置
vscode 开发c++存在两种插件模式:¶
(1) vscode c++: 微软官方 (2) clangd + codeLLDB:更强悍 其他插件: Cmake用于编译项目。 Remote Explorer:连接远程开发机器,连接docker,连接docker比Clion更友好,可以进入已经存在的Container,而Clion会新启动一个Container。 常用快捷键: Ctrl+Shift+P:功能面板,输入Cmake,就会跳出插件支持的功能,比如:Build,Run。 Ctrl+R:切换项目 Ctrl+B:打开/关闭目录树 Ctrl-Alt+-: 回到上一个位置 调试: Ctrl+Shift+D点左边栏的debug按钮,然后应该会自动生成一个launch.json。可以安装一个调试脚本自动生成插件,然后在基础上修改,如修改可执行文件位置,gdb执行文件等。还可以配置远程gdbserver,vscode连接gdbserver进行调试。 参考:https://zhangjk98.xyz/vscode-c-and-cpp-develop-and-debug-setting/。 常见问题:
- 采用c/c++插件时,如果代码不能跳转到定义位置,一般是没有打开Intelligence,参考:右键代码无跳转,Vscode右键无代码跳转问题。
- 采用clangd插件时,代码不能跳转定义位置,vscode 中用clang遇到问题:clang(pp_file_not_found),clangd 插件设置中加入参数: –compile-commands-dir=${workspaceFolder}/build/ 帮你找到compile_commands.json。该文件通过设置Cmake插件生成,默认打开。
- 中文乱码问题,打开设置中的自动文件格式检测,关于VS Code 中文显示乱码_vscode 乱码_Sean_gGo的博客-CSDN博客。vim中也有类似的设置,vim中加入: set encoding=utf-8 fileencodings=ucs-bom,utf-8,cp936。
快捷键¶
https://cloud.tencent.com/developer/article/1885451 Ctrl-d:一个一个选择匹配到的,多光标选择修改 Ctrl-u:Ctrl-d对应的逆操作 Ctrl-g:跳转到指定行号位置 Ctrl-w:关闭Tab Ctrl-k-w:关闭所有Tab Ctrl-Shit-a:注释选中的一段代码 Ctrl-:分割窗口 Ctrl-1:切换上一个窗口 Ctrl-2:切换下一个窗口 Ctrl-Tab:切换Tab
Vscode结合Vim¶
https://www.barbarianmeetscoding.com/boost-your-coding-fu-with-vscode-and-vim
Vscode如何gdb¶
调试普通可执行程序 调试so Python加载so gdb版本也可能影响
启动server: /opt/gcc-arm-8.3-2019.03-x86_64-arm-linux-gnueabihf# find . -name gdbserver ./arm-linux-gnueabihf/libc/usr/bin/gdbserver cp gdbserver 到运行主机上 ${current_dir}/../gdbserver :9091 ${current_dir}/bin/main arg1 arg2 在开发机上: /opt/gcc-arm-8.3-2019.03-x86_64-arm-linux-gnueabihf/bin# arm-linux-gnueabihf-gdb
args 和 env设置
| C++ | |
|---|---|
Vscode配置交叉编译工具¶
| Text Only | |
|---|---|
| Text Only | |
|---|---|
gdb更好的显示c++ STL数据结构的值¶
开启pretty-print功能¶
在使用vscode调试时,不能像clion一样直接查看STL容器中的内容,比如String,只能看到指针和长度等信息,不能直接看到字符串。 【工具】——VSCODE调试C++时无法显示Vector,map等容器的值_农夫山泉2号的博客-CSDN博客
| Text Only | |
|---|---|
| Text Only | |
|---|---|
- 重新编译
| Text Only | |
|---|---|