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"
}
相关推荐
感哥10 小时前
C++ STL 常用算法
c++
saltymilk21 小时前
C++ 模板参数推导问题小记(模板类的模板构造函数)
c++·模板元编程
感哥21 小时前
C++ lambda 匿名函数
c++
沐怡旸1 天前
【底层机制】std::unique_ptr 解决的痛点?是什么?如何实现?怎么正确使用?
c++·面试
感哥1 天前
C++ 内存管理
c++
博笙困了1 天前
AcWing学习——双指针算法
c++·算法
感哥1 天前
C++ 指针和引用
c++
感哥2 天前
C++ 多态
c++
沐怡旸2 天前
【底层机制】std::string 解决的痛点?是什么?怎么实现的?怎么正确用?
c++·面试
River4162 天前
Javer 学 c++(十三):引用篇
c++·后端