Vscode C++ 配置

task.json

https://code.visualstudio.com/docs/editor/tasks

{
    "tasks": 
           [{          
                "label": "Build",  // 与launch preLaunchTask一致
                "type": "shell",  // shell命令
                "request": "launch", // launch(启动)或 attach(附加)
                "command": "g++", // 命令是g++
                "args": [
                       "-g",
                       "'${file}'", // 当前文件名
                       "-o", // 对象名,不进行编译优化
                       "'${fileBasenameNoExtension}'",  //当前文件名(去掉扩展名)
                ],
                "options":{
                     "cwd": "${workspaceFolder}" //current working directory
                     // env (environment variables)
                     // shell (default shell) 
                },
                "group": { 
                      "kind": "build",
                      "isDefault": true   
                },
                "problemMatcher": [
                      "$gcc" // 使用gcc捕获错误
                ],
            }]  
}

lanuch.json

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Build", 
            "preLaunchTask": "Build",  //tasks.json任务名一致
            "type": "cppdbg",
            "request": "launch",
            "program": "${fileBasenameNoExtension}",
            "args": [],
            "stopAtEntry": false, // 暂时不执行程序
            "cwd": "${workspaceFolder}", 
            "environment": [],
            "externalConsole": false, 
            "MIMode": "gdb",
            "miDebuggerPath": "/usr/bin/gdb",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ]
        }
    ]
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

友情链接更多精彩内容