vscode(四):调试、编译C/C++

一、环境准备

参数含义:
32位系统选择i686, 64位系统选择x86_64
线程模型:win32 : 没有C ++ 11多线程特性, posix : 支持C ++ 11多线程特性
异常处理模型:32位系统推荐dwarf,64位系统推荐seh
因为测试环境为64位系统,所以推荐配置为x86_64-posix-seh

下载完以后解压到你自定义的路径下,将你自定义的路径/mingw64/bin目录添加到系统环境的path下面

  • clang(推荐)或gcc
二、vscode配置
  • 新建的项目是没有task.json和launch.json这两个文件的
    创建文件的方法: ctrl+shift+p打开命令行
    分别输入task和launch两个命令
    在这里插入图片描述
    在这里插入图片描述

  • task.json→作用:构建、编译程

  • c的配置

  • c++的配置

{
    //the c configuration
    "version": "2.0.0",
    "tasks": [
        {
            "type": "shell",
            "label": "gcc.exe build active file",
            "command": "D:\\Program Files (x86)\\mingw64\\bin\\gcc.exe", //这里换成你的MinGW安装地址
            "args": [
           		"-Wall", // 开启 -Wall 选项
                "-g",
                "${file}",
                "-o",
                "${fileDirname}\\${fileBasenameNoExtension}.exe" 
            ], //这里是编译命令参数 gcc -Wall -g  -o  xx.exe
            "options": {
                "cwd": "D:\\Program Files (x86)\\mingw64\\bin" //MinGW的bin目录位置
            },
            "problemMatcher": [
                "$gcc"  
            ],
            "group": "build"
        }
    ]
}
{
    //the c++ configuration
    "version": "2.0.0",
    "tasks": [
        {
            "type": "shell",
            "label": "g++.exe build active file",
            "command": "D:\\Program Files (x86)\\mingw64\\bin\\g++.exe", //这里换成你的MinGW安装地址
            "args": [
           		"-Wall", // 开启 -Wall 选项
                "-g",
                "${file}",
                "-o",
                "${fileDirname}\\${fileBasenameNoExtension}.exe" 
            ], //这里是编译命令参数 gcc -Wall -g  -o  xx.exe
            "options": {
                "cwd": "D:\\Program Files (x86)\\mingw64\\bin" //MinGW的bin目录位置
            },
            "problemMatcher": [
                "$gcc"  
            ],
            "group": "build"
        }
    ]
 }
  • launch.json→作用:运行、调试程序
  • c的配置
  • c++的配置
{
    //the c configuration
    "version": "0.2.0",
    "configurations": [
        {
            "name": "gcc.exe build and debug active file",
            "type": "cppdbg",
            "request": "launch",
            "program": "${fileDirname}\\${fileBasenameNoExtension}.exe", //
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": false, // true时,运行时会打开CMD窗口来显示运行结果
            "MIMode": "gdb",
            "miDebuggerPath": "D:\\Program Files (x86)\\mingw64\\bin\\gdb.exe",  //同样要设置为 MinGW 的安装目录内bin/gdb.exe的绝对路径
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
            "preLaunchTask": "g++.exe build active file"
        }
    ]
}
{
    //the c++ configuration
    "version": "0.2.0",
    "configurations": [
        {
            "name": "g++.exe build and debug active file",
            "type": "cppdbg",
            "request": "launch",
            "program": "${fileDirname}\\${fileBasenameNoExtension}.exe", //
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": false, // true时,运行时会打开CMD窗口来显示运行结果
            "MIMode": "gdb",
            "miDebuggerPath": "D:\\Program Files (x86)\\mingw64\\bin\\gdb.exe",  //同样要设置为 MinGW 的安装目录内bin/gdb.exe的绝对路径
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
            "preLaunchTask": "g++.exe build active file"
        }
    ]
}
  • 插件(C/C++)
    需要以下两个插件
    在这里插入图片描述

  • 设置程序运行在终端
    文件→首选项→设置→用户→扩展→run code configuration→run in Terminal前面打勾

  • 具体的项目配置工程模板链接
    cpp的工程模板

三、使用

F5一键编译

三、Makefile配置
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值