Linux下VS Code的C++工程配置

准备

安装vscode,可直接下载deb包进行安装,完成后安装C/C++ for Visual Studio Code插件,安装后重启最新1.3版本以后不需要重启)。
Linux下VS Code的C++工程配置

生成目录文件

新建文件夹【test】,并新建文件helloworld.cpp文件,文件中内容如下,

#include <iostream>  #include <string>  using namespace std;  int main(int argc, char const *argv[])  {      cout<< "hello world" << endl;      return 0;  }

使用vscode打开文件夹
Linux下VS Code的C++工程配置

配置c++ IntelliSense

使用F1,打开命令选项,输入C/C++,选择C/C++:Edit configuration,生成c_cpp_properties.json配置文件。

Linux下VS Code的C++工程配置

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

其中最主要为”includePath”的引用和库的路径,根据引用内容进行配置。

launch

在debug界面中选择添加配置,然后选择才c++(gdb/lgdb)选项,生成launch.json 顾名思义此文件主要服务于调试时的加载控制

Linux下VS Code的C++工程配置

{      "version": "0.2.0",      "configurations": [          {              "name": "(gdb) Launch",              "type": "cppdbg",              "request": "launch",              "program": "${workspaceFolder}/helloworld",              "args": [],              "stopAtEntry": false,              "cwd": "${workspaceFolder}",              "environment": [],              "externalConsole": true,              "MIMode": "gdb",              "preLaunchTask": "build",              "setupCommands": [                  {                      "description": "Enable pretty-printing for gdb",                      "text": "-enable-pretty-printing",                      "ignoreFailures": true                  }              ]          }      ]  }

需要注意的参数为”program”,此为需要调试的目标文件,应当设置为编译输出的文件位置;其次需要添加”preLaunchTask”,此项的名字应与下面所建的tasks.json中的任务名称一致。

tasks.json

在命令窗口中输入task,选择task: configure task选项生成tasks.json文件

Linux下VS Code的C++工程配置

{      "version": "2.0.0",      "tasks": [          {              "label": "build",              "type": "shell",              "command": "g++",              "args":[                  "-g","helloworld.cpp","-o","helloworld"              ],              "group": {                  "kind": "build",                  "isDefault": true              }          }      ]  }

注意launch.json中的”preLaunchTask”调用与“label”相同的task。

开始调试

按下F5开始调试吧,一切就是这么简单,开始美好的旅程。

Linux下VS Code的C++工程配置

下载安装见 Visual Studio Code 1.29 发布,支持多行搜索  https://www.linuxidc.com/Linux/2018-11/155411.htm

Visual Studio Code的Python扩展发布,增强的变量资源管理器数据查看器  https://www.linuxidc.com/Linux/2019-04/158376.htm

微软正式为Linux用户发布Visual Studio Code  https://www.linuxidc.com/Linux/2019-04/157953.htm

Visual Studio Code添加Java 12支持,Java代码操作语言功能  https://www.linuxidc.com/Linux/2019-05/158495.htm

收藏 (0) 打赏

感谢您的支持,我会继续努力的!

打开微信/支付宝扫一扫,即可进行扫码打赏哦,分享从这里开始,精彩与您同在
点赞 (0)

栗子博客 软件 Linux下VS Code的C++工程配置 https://www.lizi.tw/soft/15178.html

常见问题
  • 1、杰齐1.7仅适用于PHP5.2 2、需Zend支持 3、尽量使用宝塔面板 4、尽量使用Windows 系统,关关对Linux支持不太友好。
查看详情

相关文章

评论
暂无评论
官方客服团队

为您解决烦忧 - 24小时在线 专业服务

Linux下VS Code的C++工程配置-海报

分享本文封面