VSCode 和 CLion 探索

官网

Visual Studio Code - Code Editing. Redefined

Documentation for Visual Studio Code 官网帮助文档

使用VScode运行C/C++,你可能要安装这些插件

【VScode】搜索栏语法_vscode files.exclude_一颗不甘坠落的流星的博客-CSDN博客

vscode工程屏蔽不需要的文件(保持搜索便利)_vscode排除文件夹_蓁蓁啊的博客-CSDN博客

vsCode离线安装remote-ssh插件和搭建远程开发环境 - 爱码网

vscode调试时以16进制查看变量_vscode调试查看变量_虔诚的学习者的博客-CSDN博客

简单的 VSCode 插件离线安装方法_乘风破浪kk的博客-CSDN博客

VSCode使用IDEA快捷键,IntelliJ IDEA Keybindings插件使用方法_vscode导入idea快捷键_Magicflowersbloom的博客-CSDN博客

 VScode 使用之自动生成文件注释_vscode自动生成注释_会打莎士比亚的猴子的博客-CSDN博客

Doxygen与Vscode操作全解_51CTO博客_vscode使用

【Doxygen】Vscode 插件 DoxyGen Documentation Generator C语言详细设置_doxygen vscode_苏打豆的博客-CSDN博客

Visual Studio Code(VScode)自动生成头文件的 #ifndef #define #endif - 行业资讯 - 电子产品设计开发与电子技术学习交流!

vscode + cmake命令行参数debug_cmake 命令行 参数_wakaka_Yu的博客-CSDN博客

如何在vscode中将命令行参数传递给cmake?-腾讯云开发者社区-腾讯云


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 探索_第1张图片
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-的博客-CSDN博客


使用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
                }
            ]
        }
    ]
}

msvc

{
    "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 探索_第2张图片

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

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

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

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

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

 (5)生成 .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 和 CLion 探索_第3张图片

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

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

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

VSCode 和 CLion 探索_第4张图片

 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  

clion无限重置试用插件_哪都通临时员工的博客-CSDN博客_clion 无限试用

clion/ide 正版过期重置时间(适合2021.2.2及以下,3的不行)_爱吃李子010的博客-CSDN博客_clion使用到期

Clion 打开Qt的ui文件_L-Super的博客-CSDN博客_clion ui

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

解决 CLion 远程调试时,debug信息乱码的问题_非攻墨门的博客-CSDN博客

你可能感兴趣的:(C++,vscode,ide,编辑器)