vscode cpptools路径修改_[工具类]VSCode C++编译调试环境

本文介绍了如何在VSCode中搭建C++编译调试环境,重点关注.c_cppproperties.json, launch.json, tasks.json和settings.json的配置。同时提供了MingW的下载链接,并建议参考官方文档进行调试设置。" 124555032,9298023,图形学中的线性代数基础:从向量到变换,"['线性代数', '几何学', '矩阵', '图形学']
摘要由CSDN通过智能技术生成

a486679aa5574818f5b7ba6dfb67a94f.png

VSCode 搭建C++编译调试环境主要包括.vscode文件夹下面三个文件,下面是可以调试C++并发编程的配置

  • c_cppproperties.json
{
    "configurations": [
        {
            "name": "Win32",
            "includePath": [
                "${workspaceFolder}/**"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "_UNICODE"
            ],
            "compilerPath": "C:mingw-w64mingw32bingcc.exe",
            "cStandard": "c11",
            "cppStandard": "c++17",
            "intelliSenseMode": "gcc-x64"
        }
    ],
    "version": 4
}
  • 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
    // https://github.com/Microsoft/vscode-cpptools/blob/master/launch.md
    "version": "0.2.0",
    "configurations": [
        {
            "name": "(gdb) Launch", // 配置名称,将会在启动配置的下拉菜单中显示
            "type": "cppdbg",// 配置类型,这里只能为cppdbg
            "request": "launch", // 请求配置类型,可以为launch(启动)或attach(附加)
            "program": "${fileDirname}/${fileBasenameNoExtension}.exe", // 将要进行调试的程序的路径
            "miDebuggerPath": "C:mingw-w64mingw32bingdb.exe", // 修改为本机gdb.exe的路径
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "externalConsole": true,
            "environment": [],
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
            "preLaunchTask": "Build"
        }
    ]
}
  • tasks.json
{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "Build",
            "command": "C:mingw-w64mingw32bing++.exe", // 修改这里为本机g++路径
            "type": "shell",
            "args": [
                "-g",
                "-Wall",
                "-std=c++11",
                "-lm",
                "${file}",
                "-o",
                "${fileDirname}/${fileBasenameNoExtension}.exe" //Linux和macOS这里要修改为.o
            ],
            "presentation": {
                "reveal": "always",
                "echo": true,
                "focus": true
            },
            "problemMatcher": {
                "owner": "cpp",
                "fileLocation": ["relative", "${workspaceRoot}"],
                "pattern": {
                    "regexp": "^(.*):(d+):(d+):s+(warning|error):s+(.*)$",
                    "file": 1,
                    "line": 2,
                    "column": 3,
                    "severity": 4,
                    "message": 5
                }
            },
            "group": {
                "kind": "build",
                "isDefault": true
            }
        }, 

        {
            "label": "Run",
            "type": "shell",
            "dependsOn": "Build",
            // "command": "${fileDirname}/${fileBasenameNoExtension}.o",
            "command":"${fileDirname}/${fileBasenameNoExtension}.exe",
            //"command": "gcc -Wall "$file" -o "$file_base_name" && start cmd /c ""${file_path}/${file_base_name}" & pause"",
            // "windows": {
            //     "command": "${fileDirname}/${fileBasenameNoExtension}.exe"
            // },
            "args": [],
            "presentation": {
                "reveal": "always",
                "focus": true
            },
            "problemMatcher": [],
            "group": {
                "kind": "test",
                "isDefault": true
            }
        }
    ]
}
  • settings.json
{
    "files.associations": {
        "*.tcc": "cpp",
        "istream": "cpp",
        "ostream": "cpp",
        "iostream": "cpp",
        "array": "cpp",
        "atomic": "cpp",
        "hash_set": "cpp",
        "bitset": "cpp",
        "cctype": "cpp",
        "clocale": "cpp",
        "cmath": "cpp",
        "cstdarg": "cpp",
        "cstddef": "cpp",
        "cstdint": "cpp",
        "cstdio": "cpp",
        "cstdlib": "cpp",
        "cstring": "cpp",
        "cwchar": "cpp",
        "cwctype": "cpp",
        "deque": "cpp",
        "unordered_map": "cpp",
        "vector": "cpp",
        "exception": "cpp",
        "algorithm": "cpp",
        "iterator": "cpp",
        "map": "cpp",
        "memory": "cpp",
        "memory_resource": "cpp",
        "optional": "cpp",
        "set": "cpp",
        "string": "cpp",
        "string_view": "cpp",
        "system_error": "cpp",
        "tuple": "cpp",
        "type_traits": "cpp",
        "utility": "cpp",
        "fstream": "cpp",
        "initializer_list": "cpp",
        "iosfwd": "cpp",
        "limits": "cpp",
        "new": "cpp",
        "sstream": "cpp",
        "stdexcept": "cpp",
        "streambuf": "cpp",
        "typeinfo": "cpp",
        "thread": "cpp",
        "chrono": "cpp"
    }
}

下面是mingw的下载地址

https://sourceforge.net/projects/mingw/

http://mingw-w64.org/doku.phpDebug C++ in Visual Studio Codehttp://mingw-w64.org/doku.php

具体可以参考官方的文档 Debug C++ in Visual Studio Code

Debug C++ in Visual Studio Code​code.visualstudio.com
e3dc169ddc3bd9b07392679e65c5fbd8.png
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值