VsCode c++多文件编译 launch.json和task.json

//launch.json

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {//这个大括号里是我们的‘调试(Debug)’配置
        "name": "Debug", // 配置名称
        "type": "cppdbg", // 配置类型,cppdbg对应cpptools提供的调试功能;可以认为此处只能是cppdbg
        "request": "launch", // 请求配置类型,可以为launch(启动)或attach(附加)
        "program": "${fileDirname}\bin\${fileBasenameNoExtension}.exe", // 将要进行调试的程序的路径
        "args": [], // 程序调试时传递给程序的命令行参数,这里设为空即可
        "stopAtEntry": false, // 设为true时程序将暂停在程序入口处,相当于在main上打断点
        "cwd": "${workspaceFolder}", // 调试程序时的工作目录,此处为源码文件所在目录
        "environment": [], // 环境变量,这里设为空即可
        "externalConsole": false, // 为true时使用单独的cmd窗口,跳出小黑框;设为false则是用vscode的内置终端,建议用内置终端
        "internalConsoleOptions": "neverOpen", // 如果不设为neverOpen,调试时会跳到“调试控制台”选项卡,新手调试用不到
        "MIMode": "gdb", // 指定连接的调试器,gdb是minGW中的调试程序
        "miDebuggerPath": "F:\Program Files\mingw64\bin\gdb.exe", // 指定调试器所在路径,如果你的minGW装在别的地方,则要改成你自己的路径,注意间隔是\
        "preLaunchTask": "build" ,// 调试开始前执行的任务,我们在调试前要编译构建。与tasks.json的label相对应,名字要一样
        "setupCommands": [
            {
                "description": "Enable pretty-printing for gdb",
                "text": "-enable-pretty-printing",
                "ignoreFailures": true
            }
          ]
        }
    ]
}

//task.json

{
	"version": "2.0.0",
	"tasks": [
		{
			"type": "cppbuild",
			"label": "C/C++: g++.exe 生成活动文件",
			"command": "F:\Program Files\mingw64\bin\g++.exe",
			"args": [
				"-fdiagnostics-color=always",
				"-g",
				"${workspaceFolder}\*.cpp",
				"-I",
				"${workspaceFolder}\include\",      //指定包含文件的目录
				"-o",
				"${fileDirname}\bin\${fileBasenameNoExtension}.exe",
				"-std=c++11"
			],
			"options": {
				"cwd": "${fileDirname}"
			},
			"problemMatcher": [
				"$gcc"
			],
			"group": {
				"kind": "build",
				"isDefault": true
			},
			"presentation": {
                "echo": true,
                "reveal": "always",
                "focus": false,
                "panel": "shared"
            },
			"detail": "编译器: "F:\Program Files\mingw64\bin\g++.exe""
		}
	]
}

c_cpp_properties.json

{

    "configurations": [

        {

            "name": "Win32",

            "includePath": [

                "${workspaceFolder}/**"

            ],

            "defines": [

                "_DEBUG",

                "UNICODE",

                "_UNICODE"

            ],

            "compilerPath": "F:\Program Files\mingw64\bin\gcc.exe",

            "cStandard": "c17",

            "cppStandard": "gnu++14",

            "intelliSenseMode": "windows-gcc-x64"

        }

    ],

    "version": 4

}
经验分享 程序员 微信小程序 职场和发展