VSCode 和 CLion
  KUhs7mNfc72R 2023年11月02日 66 0


VSCode 和 CLion_vscode



文章目录

  • 一、VSCode
  • 1、文档
  • 2、插件
  • 3、智能编写
  • 4、VSCode 与 C++
  • (1)安装
  • (2)调试
  • (a)使用 CMake 进行跨平台编译与调试
  • (b)launch.json
  • (c)传参
  • (3)clang-format
  • 5、VSCode 与 Qt
  • (1)使用
  • (2)问题
  • 6、code-server
  • 二、CLion



一、VSCode

1、文档

官网官网帮助文档VSCode 精品教程

2、插件

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

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

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

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

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

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

VSCode使用IDEA快捷键,IntelliJ IDEA Keybindings插件使用方法

VSCode 和 CLion_ide_02

VSCode 中文乱码设置

3、智能编写

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

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

Vscode 插件 DoxyGen Documentation Generator C语言详细设置_doxygen vscode

Visual Studio Code(VScode)自动生成头文件

4、VSCode 与 C++

(1)安装

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++'。
  4. VSCode 和 CLion_ide_03

  5. 选择安装。

(2)调试

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

Get started with CMake Tools on Linuxvscode-cmake-tools/README.md at main · microsoft/vscode-cmake-tools · GitHubVisual Studio Code Variables Reference用VSCode和CMake编写调试C/C++ - 简书vscode+cmake下debug报错Target debugging is no longer supported with the legacy driver

(b)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"
        }
    ]
}
(c)传参

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

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

(3)clang-format

    各个 IntelliSense 都有自己的代码格式化,可以不使用 clang-format 进行格式化,此处列出备用。

  1. 下载插件
  2. 下载 clang-format
    linux
sudo apt-get install clang-format
  1. 设置
    (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,并在保存时自动格式化代码的方法(带配置文件)

5、VSCode 与 Qt

(1)使用

  1. 使用 Qtcreator 创建 cmake 工程
  2. VSCode 和 CLion_Qt_04

  3. 用vscode开发qt linux系统使用vscode进行qt开发
  4. 如何使用VSCode开发Qt项目?_神奇小邓的博客
  5. 生成的文件大致如下
  6. VSCode 和 CLion_编辑器_05

  7. 启动VSCode
    打开终端(cmd或bash),进入当前代码所在的文件夹,输入
# 设置Qt运行库的环境变量
set PATH=%PATH%;D:/Qt6/6.2.2/msvc2019_64/bin
 
# 运行VSCode
code .
  1. 生成与调试
    参考前面的cmake生成与调试

(2)问题

  • 找不到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)
  • 运行找不到 Qt 库
    在环境变量中添加Qt运行库路径
    或者 在终端中设置QT运行库路径到环境变量中,然后启动 VSCode

6、code-server

服务器部署code-servergithub code-server

linux 下启动 code-server

#!/bin/bash
#pid=`pgrep code-server`
pid=`ps aux | grep /usr/lib/code-server | grep -v grep`
if test "$pid" ;then
        echo $pid
        echo code-server already running...
else
        echo $pid
        echo Will run code-server
        code-server &
fi

二、CLion

官方文档 Learn CLionQuick start guide | CLion其他版本 - CLion

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

clion/ide 正版过期重置时间(适合2021.2.2及以下,3的不行)

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

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

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

   

123

【版权声明】本文内容来自摩杜云社区用户原创、第三方投稿、转载,内容版权归原作者所有。本网站的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@moduyun.com

  1. 分享:
最后一次编辑于 2023年11月08日 0

暂无评论

推荐阅读
  anLrwkgbyYZS   2023年12月30日   33   0   0 ideciciMaxideMax
KUhs7mNfc72R