当前位置: 首页 > article >正文

Linux 下VS Code 的使用

这里以创建helloworld 为例。

Step 0:准备工作:

  1. Install Visual Studio Code.

  2. Install the C++ extension for VS Code. You can install the C/C++ extension by searching for 'c++' in the Extensions view (Ctrl+Shift+X).

Step 1: 创建工作目录 helloworld,并启动vscode

mkdir helloworld
cd helloworld
code .

Step 2: 工作目录helloworld 下会生成一个.vscode 文件夹,其中需要三个关键的配置文件:

  • tasks.json (compiler build settings)
  • launch.json (debugger settings)
  • c_cpp_properties.json (compiler path and IntelliSense settings)

  (1)tasks.json stores build configurations.

The first time you run your program, the C++ extension creates tasks.json

例子如下

{"version": "2.0.0","tasks": [{"type": "shell","label": "C/C++: g++ build active file","command": "/usr/bin/g++","args": ["-g", "${file}", "-o", "${fileDirname}/${fileBasenameNoExtension}"],"options": {"cwd": "/usr/bin"},"problemMatcher": ["$gcc"],"group": {"kind": "build","isDefault": true},"detail": "Task generated by Debugger."}]
}

(2)launch.json 存储 debug 配置信息

To create launch.json, choose Add Debug Configuration from the play button drop-down menu.

例子如下:

{"version": "0.2.0","configurations": [{"name": "C/C++: g++ build and debug active file","type": "cppdbg","request": "launch","program": "${fileDirname}/${fileBasenameNoExtension}","args": [],"stopAtEntry": false,"cwd": "${workspaceFolder}","environment": [],"externalConsole": false,"MIMode": "gdb","miDebuggerPath": "/usr/bin/gdb","setupCommands": [{"description": "Enable pretty-printing for gdb","text": "-enable-pretty-printing","ignoreFailures": true}],"preLaunchTask": "C/C++: g++ build active file"}]
}

From now on, the play button and F5 will read from your launch.json file when launching your program for debugging.

(3)c_cpp_properties.json  C/C++ configurations

If you want more control over the C/C++ extension, you can create a c_cpp_properties.json file, which will allow you to change settings such as the path to the compiler, include paths, C++ standard (default is C++17), and more.

You can view the C/C++ configuration UI by running the command C/C++: Edit Configurations (UI) from the Command Palette (Ctrl+Shift+P).

Command Palette

You only need to modify the Include path setting if your program includes header files that are not in your workspace or in the standard library path.例子如下:

{"configurations": [{"name": "Linux","includePath": ["${workspaceFolder}/**"],"defines": [],"compilerPath": "/usr/bin/gcc","cStandard": "c11","cppStandard": "c++17","intelliSenseMode": "clang-x64"}],"version": 4
}

 VS Code is now configured to use gcc on Linux. The configuration applies to the current workspace. To reuse the configuration, just copy the JSON files to a .vscode folder in a new project folder (workspace) and change the names of the source file(s) and executable as needed.

Ubuntu 下使用clang 作为vscode 的编译器,可参考如下链接进行设置:

How To Use clang With vscode On Ubuntu 20.04 | Robs Blog (rob-blackbourn.github.io)

http://www.lryc.cn/news/2387172.html

相关文章:

  • Android开发namespace奇葩bug
  • watchEffect
  • Qt 布局管理器的层级关系
  • Android 之 kotlin 语言学习笔记一
  • maven模块化开发
  • 为什么要使用stream流
  • 语义分割的image
  • 云原生安全之网络IP协议:从基础到实践指南
  • C++——QT 文件操作类
  • 【排错】kylinLinx环境python读json文件报错UTF-8 BOM
  • [spring] spring 框架、IOC和AOP思想
  • LInux—shell编程
  • 尚硅谷redis7 37-39 redis持久化之AOF简介
  • GitLab 备份所有仓库(自动克隆)
  • [浏览器]缓存策略机制详解
  • Vue修饰符全解析
  • OpenCV CUDA 模块图像过滤-----创建一个计算图像导数的滤波器函数createDerivFilter()
  • 计算机视觉与深度学习 | Python实现CEEMDAN-ABC-VMD-DBO-CNN-LSTM时间序列预测(完整源码和数据)
  • AWS関連職種向け:日本語面接QA集
  • 【Macos】安装前端环境rust+node环境
  • (01)华为GaussDB((基于PostgreSQL))高斯数据库使用记录,dbeaver客户端配置高斯驱动,连接高斯数据库
  • ARM Linux远程调试
  • day24Node-node的Web框架Express
  • Webpack和Vite构建工具有什么区别?各自的优缺点是什么
  • 让MySQL更快:EXPLAIN语句详尽解析
  • 基于谷歌浏览器的Web Crypto API生成一对2048位的RSA密钥(公钥+私钥),并以JSON格式(JWK)打印到浏览器控制台
  • [CSS3]rem移动适配
  • 向量数据库及ChromaDB的使用
  • CodeBuddy实现pdf批量加密
  • 编程中优秀大模型推荐:特点与应用场景深度分析