VSCode C/C++多文件编译配置

多文件编译备忘,带注释的地方都需要注意!!!

launch.json文件

cpp 复制代码
{
    // 使用 IntelliSense 了解相关属性。 
    // 悬停以查看现有属性的描述。
    // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "g++.exe - 生成和调试活动文件",
            "type": "cppdbg",
            "request": "launch",
            "program": "${fileDirname}/out.exe",//1、 文件目录   执行程序.exe路径
            "args": [],
            "stopAtEntry": false,
            "cwd": "${fileDirname}", //2、文件目录
            "environment": [],
            "externalConsole": true, //3、 显示控制台窗口
            "MIMode": "gdb",
            "miDebuggerPath": "D:\\App\\Microsoft VS Code\\mingw64\\bin\\gdb.exe", //4、 gdb.exe路径
            "setupCommands": [
                {
                    "description": "为 gdb 启用整齐打印",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                },
                {
                    "description": "将反汇编风格设置为 Intel",
                    "text": "-gdb-set disassembly-flavor intel",
                    "ignoreFailures": true
                }
            ],
            "preLaunchTask": "C/C++: g++.exe 生成活动文件" //链接task.json,这个名称必须要与task.json中的label名称一致否则会编译出错
        }
    ]
}

task.json文件

cpp 复制代码
{
    "tasks": [
        {
            "type": "cppbuild",
            "label": "C/C++: g++.exe 生成活动文件",  //1、 与launch.json中preLaunchTask的名称一致
            "command": "D:\\App\\Microsoft VS Code\\mingw64\\bin\\g++.exe", //2、 c++编译器g++.exe的路径
            "args": [
                "-fdiagnostics-color=always",
                "-g",
                "${fileDirname}/*.cpp", //"${file}", //多文件编译
                "-o",
                "${fileDirname}/out.exe" //"${fileDirname}\\${fileBasenameNoExtension}.exe" //多文件编译成功生成的可执行文件.exe
                
            ],
            "options": {
                "cwd": "${fileDirname}"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "detail": "调试器生成的任务。"
        }
    ],
    "version": "2.0.0"
}
相关推荐
QT 小鲜肉13 分钟前
【Git、GitHub、Gitee】按功能分类汇总Git常用命令详解(超详细)
c语言·网络·c++·git·qt·gitee·github
派大星爱吃猫16 分钟前
C++中的inline函数(内联函数)
c++·inline·内联函数
清风wxy26 分钟前
Duilib_CEF桌面软件实战之Duilib编译与第一个界面程序
c++·笔记·ui·mfc
郝学胜-神的一滴27 分钟前
Linux下,获取子进程退出值和异常终止信号
linux·服务器·开发语言·c++·程序人生
notfindjob1 小时前
MFC动态加载图片
c++·mfc
CodeByV1 小时前
【C++】继承
开发语言·c++
乱舞八重击(junluoyu)2 小时前
1.PagedAtteion算法
c++
2301_803554523 小时前
C++ 锁类型大全详解
开发语言·c++
曼巴UE53 小时前
UE5 C++ Slate 画曲线
开发语言·c++·ue5
ue星空3 小时前
UE5C++UKismetMathLibrary源代码
c++·ue5