wsl vscode下调试c++文件配置

  1. launch.json
{
   
    "version": "0.2.0",
    "configurations": [
      {
   
        "name": "(gdb) Launch",
        "type": "cppdbg",
        "request": "launch",
        "program": "${workspaceFolder}/helloworld.out",
        "args": [""],
        "stopAtEntry": true,
        "cwd": "${workspaceFolder}",
        "environment": [],
        "externalConsole": true,
        "windows": {
   
          "MIMode": "gdb",
          "miDebuggerPath": "/usr/bin/gdb",
          "setupCommands"
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
WSL是指Windows Subsystem for Linux,它允许在Windows系统上运行Linux子系统。在WSL2中,VS Code可以配置为在WSL下的Ubuntu系统中编写C程序。配置步骤如下: 1. 首先,确保已经安装了WSL2和Ubuntu子系统。可以通过Microsoft Store下载并安装WSL2,然后在Microsoft Store中搜索Ubuntu并安装。 2. 打开VS Code,在扩展商店中搜索并安装"Remote - WSL"扩展。 3. 在VS Code中打开一个文件夹,并点击左下角的绿色按钮,选择"Remote-WSL: New Window",这将打开一个新的VS Code窗口,连接到WSL中的Ubuntu系统。 4. 在WSL中的Ubuntu系统中,安装必要的C编译工具。打开终端并运行以下命令: ``` sudo apt update sudo apt install build-essential ``` 5. 在VS Code中,打开C程序文件,并确保文件保存在WSL中的Ubuntu系统中的文件夹中。 6. 在VS Code中按下Ctrl+Shift+B,选择"Tasks: Configure Default Build Task",然后选择"Create tasks.json file from template",再选择"Others"。 7. 在tasks.json文件中,将以下代码粘贴到"tasks"数组中: ```json { "label": "Build and run", "type": "shell", "command": "gcc", "args": [ "-g", "${file}", "-o", "${fileDirname}/${fileBasenameNoExtension}" ], "group": { "kind": "build", "isDefault": true }, "problemMatcher": [] } ``` 8. 保存并关闭tasks.json文件。 现在,您可以在WSL下的Ubuntu系统中编写和运行C程序了。按下Ctrl+Shift+B进行编译,并在终端中运行生成的可执行文件
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值