visual studio code配置c/c++编译环境

MinGW-w64下载版本为:tdm64-gcc-5.1.0-2.exe,安装在c盘根目录。TDM-GCC MinGW Compiler

我的配置如下:
.vscode\c_cpp_properties.json文件:

{
    "configurations": [
        {
            "name": "Win32",
            "browse": {
                "path": [
                    "${workspaceFolder}",
                    "C:/TDM-GCC-64/x86_64-w64-mingw32/include",
                    "C:/TDM-GCC-64/lib/gcc/x86_64-w64-mingw32/5.1.0/include/c++",
                    "C:/TDM-GCC-64/lib/gcc/x86_64-w64-mingw32/5.1.0/include/c++/backward",
                    "C:/TDM-GCC-64/lib/gcc/x86_64-w64-mingw32/5.1.0/include/c++/tr1",
                    "C:/TDM-GCC-64/lib/gcc/x86_64-w64-mingw32/5.1.0/include",
                    "C:/TDM-GCC-64/lib/gcc/x86_64-w64-mingw32/5.1.0/include/c++/x86_64-w64-mingw32"
                ],
                "limitSymbolsToIncludedHeaders": true,
                "databaseFilename": ""
            },
            "includePath": [
                "${workspaceFolder}",
                "C:/TDM-GCC-64/x86_64-w64-mingw32/include",
                "C:/TDM-GCC-64/lib/gcc/x86_64-w64-mingw32/5.1.0/include/c++",
                "C:/TDM-GCC-64/lib/gcc/x86_64-w64-mingw32/5.1.0/include/c++/backward",
                "C:/TDM-GCC-64/lib/gcc/x86_64-w64-mingw32/5.1.0/include/c++/tr1",
                "C:/TDM-GCC-64/lib/gcc/x86_64-w64-mingw32/5.1.0/include",
                "C:/TDM-GCC-64/lib/gcc/x86_64-w64-mingw32/5.1.0/include/c++/x86_64-w64-mingw32"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "_UNICODE",
                "__cdecl=__attribute__((__cdecl__))"
            ],
            "cStandard": "c11",
            "cppStandard": "c++17",
            "intelliSenseMode": "clang-x64",

            "compilerPath": "gcc.exe"   
        }
    ],
    "version": 4
}

.vscode\tasks.json文件:

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "g++",
            "type": "shell",
            "command": "g++",
            "args": [
                "${file}",            //        
                "-g",                 //生成和调试有关的信息
                "-std=c++11",         //c语言最新标准为c11
                "-o",                 //指定输出文件名,默认输出为a.exe
                "${fileDirname}/${fileBasenameNoExtension}.exe",
                "-Wall",              // 开启额外警告
                "-static-libgcc",     // 静态链接
                "-fcolor-diagnostics",
                "--target=x86_64-w64-mingw"
            ]
        }
    ]
}

.vscode\launch.json文件:

{
    // 使用 IntelliSense 了解相关属性。 
    // 悬停以查看现有属性的描述。
    // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "C++ Launch (GDB)",
            "type": "cppdbg",                       // 配置类型,这里只能为cppdbg
            "request": "launch",
            "program": "${fileDirname}/${fileBasenameNoExtension}.exe",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",            // 调试程序时的工作目录
            "environment": [],
            "externalConsole": true,                // 调试时是否显示控制台窗口,一般设置为true显示控制台
            "preLaunchTask": "g++",
            "MIMode": "gdb",                        // 指定连接的调试器,可以为gdb或lldb。但目前lldb在windows下没有预编译好的版本。
            "miDebuggerPath": "gdb.exe",            // 调试器路径。
            "internalConsoleOptions": "neverOpen"   // 如果不设为neverOpen,调试时会跳到“调试控制台”选项卡,你应该不需要对gdb手动输命令吧?
        }
    ]
}

出现的错误:

  1. visual studio code配置TDM-GCC-64后,编译c++文件提示namespace "std" has no member "cout"
    解决办法参考链接

你可能感兴趣的:(visual studio code配置c/c++编译环境)