【修BUG vscode C++】编译运行多个文件

报错:

  1. 目录结构
    在这里插入图片描述

  2. 报错内容
    在这里插入图片描述

  3. 问题所在

    由于本人在一个工作路径上,创建了多个子文件夹,那么编译器无法按照文件夹来进行编译和链接,因此需要修改task.json文件中的args参数

解决办法:

  1. task.json文件

{
    "version": "2.0.0",
    "tasks": [
        {
            "type": "shell",
            "label": "task g++",
            "command": "D:\\MinGW\\bin\\g++.exe",//前面的路径改成你安装的路径
            "args": [
                "-g",
                // "${file}", //注释掉fiel修改成文件空间目录下的子目录
                "${workspaceFolder}/Queue_implement/*.cpp",
                "-o",
                "${fileDirname}\\${fileBasenameNoExtension}.exe"
            ],
            "options": {
                "cwd": "D:\\MinGW\\bin"//前面的路径改成你安装的路径
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": "build"
        },
        {
            "type": "cppbuild",
            "label": "C/C++: g++.exe 生成活动文件",
            "command": "D:\\MinGW\\bin\\g++.exe",//前面的路径改成你安装的路径
            "args": [
                "-fdiagnostics-color=always",
                "-g",
                "${file}",
                "-o",
                "${fileDirname}\\${fileBasenameNoExtension}.exe"
            ],
            "options": {
                "cwd": "${fileDirname}"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "detail": "调试器生成的任务。"
        }
    ]
}
  1. launch.json
    {
    // 使用 IntelliSense 了解相关属性。 
    // 悬停以查看现有属性的描述。
    // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "g++.exe build and debug active file",
            "type": "cppdbg",
            "request": "launch",
            "program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": true,
            "MIMode": "gdb",
            "miDebuggerPath": "D:\\MinGW\\bin\\gdb.exe",//前面的路径改成你安装的路径
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
            "preLaunchTask": "task g++"
        }  
    ]
    }
    
  2. c_cpp_properties.json
    {
    "configurations": [
       {
           "name": "Win32",
           "includePath": [
               "${workspaceFolder}/**"
    
                           ],
           "defines": [
               "_DEBUG",
               "UNICODE",
               "_UNICODE"
           ],
           "compilerPath": "D:/MinGW/bin/g++.exe", //编译器路径
           "cStandard": "gnu17",
           "cppStandard": "gnu++11",
           "intelliSenseMode": "windows-gcc-x64"
       }
    ],
    "version": 4
    }
    
    
    
    
    
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值