欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

vscodec++环境配置

程序员文章站 2022-06-22 17:06:25
...

1.下载vscode安装

2.安装c/c++扩展

3.安装编译器mingw

  1. 安装好后配置环境变量
  2. cmd 命令 gcc --version 和g++ --version 测试是否安装成功

4.修改配置文件

  1. .vscode文件夹下

  2. launch.json文件

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "(gdb) Launch",
            "type": "cppdbg",
            "request": "launch",
            "program": "${fileDirname}/${fileBasenameNoExtension}.exe",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": true,
            "targetArchitecture": "x64", 
            "MIMode": "gdb",
            "miDebuggerPath": "c:\\MinGW\\bin\\gdb.exe",
            "preLaunchTask": "g++",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ]
        },
    ]
}
  1. tasks.json文件
{
    "version": "0.1.0",
    "command": "g++",
    "args": ["-g","-std=c++11","${file}","-o","${fileDirname}\\${fileBasenameNoExtension}.exe"],   // 编译命令参数
    "problemMatcher": {
        "owner": "cpp",
        "fileLocation": ["relative", "${workspaceRoot}"],
        "pattern": {
            "regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
        "file": 1,
        "line": 2,
        "column": 3,
        "severity": 4,
        "message": 5
        }
    }
}
  1. c_cpp_properties.json文件

    incoudePath根据mingw下对应的路径修改

{
    "configurations": [
        {
            "name": "Win32",
            "includePath": [
                "C:/MinGW/include",
                "C:/MinGW/lib/gcc/mingw32/6.3.0/include",
                "C:/MinGW/lib/gcc/mingw32/6.3.0/include/c++",
                "C:/MinGW/lib/gcc/mingw32/6.3.0/include/c++/backward",
                "C:/MinGW/lib/gcc/mingw32/6.3.0/include/c++/tr1",
                "C:/MinGW/lib/gcc/mingw32/6.3.0/include/c++/mingw32/bits",
                "C:/MinGW/lib/gcc/mingw32/6.3.0/include/c++/mingw32/ext",
                "C:/MinGW/lib/gcc/mingw32/6.3.0/include/c++/mingw32",
                "${workspaceFolder}/**"
            ],
            "browse": {
                "path": [
                    "${workspaceRoot}",
                    "C:/MinGW/include",
                    "C:/MinGW/lib/gcc/mingw32/6.3.0/include",
                    "C:/MinGW/lib/gcc/mingw32/6.3.0/include/c++",
                    "C:/MinGW/lib/gcc/mingw32/6.3.0/include/c++/backward",
                    "C:/MinGW/lib/gcc/mingw32/6.3.0/include/c++/tr1",
                    "C:/MinGW/lib/gcc/mingw32/6.3.0/include/c++/mingw32/bits",
                    "C:/MinGW/lib/gcc/mingw32/6.3.0/include/c++/mingw32/ext"
                ],
                "limitSymbolsToIncludedHeaders": true,
                "databaseFilename": ""
            },
            "defines": [
                "_DEBUG",
                "UNICODE",
                "_UNICODE",
                "__GNUC__=6",
                "__cdecl=__attribute__((__cdecl__))"
            ],
            "intelliSenseMode": "msvc-x64"
        }
    ],
    "version": 4
}
  1. f5调试若提示 g++已停止运行,首先到cpp文件目录,打开命令窗口,运行
g++ -g -std=c++11 xx.cpp -o xx.exe

如果提示缺少 dll文件,下载相应文件,放在mingw/bin目录下