vscode下配置c/c++开发环境

1.下载mingw64源码:

下载链接:https://sourceforge.net/projects/mingw-w64/

选中版本下载 x86_64-posix-seh  解压后将/bin下路径加入环境变量,个人环境变量和系统环境变量。

cmd中输入gcc -v查看是否安装好了mingw64

2.官网下载安装vscode

3.配置vscode安装环境

安装如下组件

3.1 配置launch.json

vscode界面点击 Debug>>Open Configurations>>c++(GDB/LLDB)会自动新建一个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": [
        {
            "name": "(gdb) Launch",
            "type": "cppdbg",
            "request": "launch",
            "program": "${fileDirname}/${fileBasenameNoExtension}.exe",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "miDebuggerPath": "D:/mingW64/mingw64/bin/gdb.exe",   //gdb 的路径
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ]
            "preLaunchTask":"build"  //名字对应编译的task
        }
    ]
}

3.2 配置task.json

生成task.json文件,修改文件如下:

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
        {
            "label": "build",
            "type": "shell",
            "command": "g++",
            "args": [
                "${file}",
                "-o",
                "${fileDirname}/${fileBasenameNoExtension}.exe",
                "-g", //生成调试信息
                "-Wall", //开启额外警告
                "-static-libgcc", //静态链接
                "-std=c++11" //c++新特性版本
            ],
            "group": "build",
            "presentation": {
                // Reveal the output only if unrecognized errors occur.
                "echo":true,
                "reveal": "always",  //在终端显示信息的策略,可以为always,silent,never
                "focus":false,  //设置为true可使执行task时焦点聚集在终端.对c/c++意义不大
                "panel": "shared" //不同的文件的编译信息共享一个终端面板
            },
            // Use the standard MS compiler pattern to detect errors, warnings and infos
            "problemMatcher": "$gcc"
        }
    ]
}

 

3.3配置c_cpp_properties.json

ctrl + shift + p -》 “C/Cpp: Edit configurations” ,生成c_cpp_properties.json 文件,修改成如下内容

{
    "configurations": [
        {
            "name": "Win32",
            "includePath": [
                "${workspaceFolder}",
                "D:/mingW64/mingw64/lib/gcc/x86_64-w64-mingw32/7.3.0/include/c++",
                "D:/mingW64/mingw64/lib/gcc/x86_64-w64-mingw32/7.3.0/include/c++/x86_64-w64-mingw32",
                "D:/mingW64/mingw64/lib/gcc/x86_64-w64-mingw32/7.3.0/include/c++/backward",
                "D:/mingW64/mingw64/lib/gcc/x86_64-w64-mingw32/7.3.0/include",
                "D:/mingW64/mingw64/x86_64-w64-mingw32/include",
                "D:/mingW64/mingw64/lib/gcc/x86_64-w64-mingw32/7.3.0/include-fixed",
                "D:/mingW64/mingw64/include"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "_UNICODE"
            ],
            "compilerPath": "D:/mingW64/mingw64/bin/g++.exe",
            "cStandard": "c11",
            "cppStandard": "c++11",
            "intelliSenseMode": "gcc-x64"
        }
    ],
    "version": 4
}

重启vscode就可以进行c/c++代码编写调试了

参考链接:https://www.cnblogs.com/ghjnwk/p/9806677.html

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值