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

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.xdnf.cn/news/8847.html

相关文章:

  • 【Python Cookbook】迭代器与生成器(二)
  • Java文件操作:从“Hello World”到“Hello File”
  • 嵌入式知识篇---热熔胶
  • 22 程序控制语句详解:跳转控制(break、continue、goto)、死循环应用、程序控制编程实战
  • SQL进阶之旅 Day 3:索引基础与应用
  • conda 环境中opencv 报错以及其他报错
  • OD 算法题 B卷【寻找最大价值的矿堆】
  • 匿名内部类与函数式编程
  • MYSQL中的分库分表
  • CQF预备知识:Python相关库 -- NumPy 基础知识 - ndarray 索引
  • MedGemma 简介
  • leetcode3-无重复字符的最长子串
  • Spring Security框架全面解析与应用实践
  • gcc编译优化参数-O0和-Os区别
  • 先知AI打造智能企业引擎
  • kaggle房价预测-0.12619-排名:757
  • ARM架构深度解析:从指令集到内核设计
  • 机械师安装ubantu双系统:二、磁盘分区
  • 小可爬楼
  • 通过 Terraform 构建您的第一个 Azure Linux 虚拟机
  • 湖仓融合的“最后一公里”:StarRocks 存算分离如何优化湖上实时分析?
  • openssl 使用生成key pem
  • 万事如函数
  • Windows File Copy
  • 第11次课 while循环
  • (27)运动目标检测 之 分类(如YOLO) 数据集自动划分
  • 关于多类型数据划分清洗的整理
  • 09_模型训练篇-卷积(上):如何用卷积为计算机“开天眼”?
  • 【C语言】指针全局变量
  • PostGIS使用小结