官网

​Visual Studio Code - Code Editing. Redefined​

​Documentation for Visual Studio Code​​ 官网帮助文档


C++

​C++ programming with Visual Studio Code​

Visual Studio Code 的 C/C++ 支持由​​Microsoft C/C++ 扩展​​提供,以在 Windows、Linux 和 macOS 上实现跨平台 C 和 C++ 开发。

安装插件

1、打开 VS 代码。

2、选择活动栏上的扩展视图图标或使用键盘快捷键 ( Ctrl+Shift+X )。

3、搜索​​'C++'​​。

VSCode 和 CLion 探索官网Get started with CMake Tools on Linux_Code


4、选择安装

使用 CMake 进行跨平台编译与调试

​Get started with CMake Tools on Linux​

​vscode-cmake-tools/README.md at main · microsoft/vscode-cmake-tools · GitHub​

​Visual Studio Code Variables Reference​

​用VSCode和CMake编写调试C/C++ - 简书​

​​vscode+cmake下debug报错Target debugging is no longer supported with the legacy driver_ccJun


使用launch.json文件进行调试

gdb


{
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
// Resolved by CMake Tools:
"program": "${command:cmake.launchTargetPath}",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [
{
// add the directory where our target was built to the PATHs
// it gets resolved by CMake Tools:
"name": "PATH",
"value": "${env:PATH}:${command:cmake.getLaunchTargetDirectory}"
},
{
"name": "OTHER_VALUE",
"value": "Something something"
}
],
"console": "externalTerminal",
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}


svc


{
"version": "0.2.0",
"configurations": [
{
"name": "(msvc) Launch",
"type": "cppvsdbg",
"request": "launch",
// Resolved by CMake Tools:
"program": "${command:cmake.launchTargetPath}",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [
{
// add the directory where our target was built to the PATHs
// it gets resolved by CMake Tools:
"name": "PATH",
"value": "${env:PATH}:${command:cmake.getLaunchTargetDirectory}"
},
{
"name": "OTHER_VALUE",
"value": "Something something"
}
],
"console": "externalTerminal"
}
]
}



VsCode clang-format

1、下载插件

VSCode 和 CLion 探索官网Get started with CMake Tools on Linux_编辑器_02

2、下载 clang-format

 linux


sudo apt-get install clang-format


3、设置

(1)首选项设置
打开首选项设置(ctrl + ,),搜索format .

(2)可勾选format on save 自动保存。

Settings > Text Editor > Formatting > Format On Save

VSCode 和 CLion 探索官网Get started with CMake Tools on Linux_ide_03

(3)C_Cpp: Clang_format_style 决定格式化形式,若为file,则调用在workspace中的.clang-format

Settings > Extensions > C/C++ > C_Cpp: Clang_format_style

VSCode 和 CLion 探索官网Get started with CMake Tools on Linux_Code_04

(4)C_Cpp: Clang_format_fallback Style ,若上图变量为file,但无.clang-format文件则按照此处规则。

Settings > Extensions > C/C++ > C_Cpp: Clang_format_fallback

VSCode 和 CLion 探索官网Get started with CMake Tools on Linux_Code_05

.clang-format

powershell中输入


clang-format -style=llvm -dump-config > .clang-format


​​VS Code C++ 代码格式化方法(clang-format)​​

​​VSCode更改格式化C++代码方式​​

​​Ubuntu下VSCode配置Clang-format,并在保存时自动格式化代码的方法(带配置文件)​​


VSCode + Qt

1、使用 Qtcreator 创建 cmake 工程

​​用vscode开发qt linux系统使用vscode进行qt开发​​

​​如何使用VSCode开发Qt项目?_神奇小邓的博客-CSDN博客_vscode开发qt​​

2、生成的文件大致如下:

VSCode 和 CLion 探索官网Get started with CMake Tools on Linux_ide_06

 3、启动VSCode

打开终端(cmd或bash),进入当前代码所在的文件夹,输入

# 设置Qt运行库的环境变量
set PATH=%PATH%;D:/Qt6/6.2.2/msvc2019_64/bin

# 运行VSCode
code .

4、生成与调试

参考前面的cmake生成与调试

5、问题

(1)找不到Qt

修改 CMakeLists.txt,添加搜索路径:

# 添加 begin
set(CMAKE_PREFIX_PATH "D:/Qt6/6.2.2/msvc2019_64")

message("CMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH}")

# 添加 end

find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets)

(2)运行找不到 Qt 库

在环境变量中添加Qt运行库路径
或者 在终端中设置QT运行库路径到环境变量中,然后启动VSCode


CLion

官方文档 ​​Learn CLion​

​Quick start guide | CLion​

​其他版本 - CLion​​  

如果 designer 打不开 ui 文件,可以把
实参(Arguments)改为 $FilePath$