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

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)

相关文章:

  • 从AD9361 到 ADSY1100 ,中间的迭代产品历史
  • 动态规划-蓝桥杯-健身
  • 大数据学习(118)-SQL面试问题总结
  • RAG系统构建之嵌入模型性能优化完整指南
  • QML学习07Property
  • vue+js 创造动态的光晕圈
  • 8:OpenCV—仿射变换和坐标映射
  • Linux的进程控制
  • 从工程实践角度分析H.264与H.265的技术差异
  • 如何将ChatGPT添加到WordPress(新手指南)
  • 大数据与数据分析【数据分析全栈攻略:爬虫+处理+可视化+报告】
  • 华为OD机试真题—— 矩阵中非1的数量 (2025B卷:200分)Java/python/JavaScript/C/C++/GO最佳实现
  • 顺丰社招入职SHL测评真题讲解| 3天备考、综合能力及性格问卷答题讲解
  • 打羽毛球tips
  • Bochs下去运行linux-0.11
  • 定时任务调度平台XXL-JOB
  • JavaSE核心知识点03高级特性03-05(注解)
  • C# Windows Forms应用程序-002
  • 2025.5.25总结
  • Linux基本指令篇 —— whoami指令
  • Python用数据库做网站/百度seo视频教程
  • 容桂网站制作代理商/网站开发的基本流程
  • 淘宝客网站做seo有用吗/百度指数数据分析
  • 手机网站开发免费视频教程/江苏网站建站系统哪家好
  • 网站建设的特色/怎么去优化关键词
  • 网站备案模板/品牌推广运营策划方案