WIN10 vscode 配置 c++

官文参考
安装mingw


在这里插入图片描述

记住鼠标悬停在配置的key上面可以看到这个配置选项是什么意思 自行一个一个去看 其实不看直接按照下面的也可以用hhh

c_cpp_properties.json

这个文件主要配置智能提示补全等等功能
比如可以增加不在当前工作空间的一些库的路径或者你自己编写的一些头文件路径用于自动补全等

{
    "configurations": [
        {
            "name": "Linux",
            "includePath": [
                "${workspaceFolder}/**"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "_UNICODE"
            ],
            "compilerPath": "xxx\\mingw64\\bin\\gcc.exe",
            "cStandard": "c11",
            "cppStandard": "c++14",
            "intelliSenseMode": "gcc-x64"
        }
    ],
    "version": 4
}

launch.json

这个是用于debug启动时的json配置
可以用preLaunchTask postDebugTask配置前后事件(在gdb之前做什么 在gdb之后做什么 比如之前的pretask可以生成exe执行文件posttask可以删除生成的exe文件)

{
    // 使用 IntelliSense 了解相关属性。 
    // 悬停以查看现有属性的描述。
    // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "g++.exe [01] build and debug active file",
            "type": "cppdbg",
            "request": "launch",
            // "program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
            "program": "${workspaceFolder}\\demo.exe",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "miDebuggerPath": "xxx\\mingw64\\bin\\gdb.exe",
            "setupCommands": [
                {
                    "description": "为 gdb 启用整齐打印",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
            "preLaunchTask": "g++.exe build active file"
        }
    ]
}

F5调试会先运行g++.exe build active file任务然后gdb调式

tasks.json

这个就是正常的任务配置了 这里是编译生成launch里面的exe执行文件
这里怎么编译你想怎么配都行

{
    "tasks": [
        {
            "type": "shell",
            "label": "g++.exe build active file",
            "command": "xxx\\mingw64\\bin\\g++.exe",
            "args": [
                "-g",
                "${file}",
                "-o",
                // "${fileDirname}\\${fileBasenameNoExtension}.exe"
                "${workspaceFolder}\\demo.exe"
            ],
            "presentation": {
                "echo": true,
                "reveal": "always",
                // "focus": false,
                "focus": true,
                "panel": "shared",
                "showReuseMessage": true,
                "clear": false
            }
        },
        //----------------------------------------------------------------
        {
            "type": "process",
            "label": "g++.exe build and run",
            "command": "${workspaceFolder}\\demo.exe",
            "args": [
            ],
            "presentation": {
                "echo": true,
                "reveal": "always",
                // "focus": false,
                "focus": true,
                "panel": "shared",
                "showReuseMessage": true,
                "clear": false
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": "build",
            "dependsOn":[
                "g++.exe build active file"
            ]
        },
    ],
    "version": "2.0.0"
}

如果不想调试想直接运行 想直接运行程序可以运行g++.exe build active file任务即可 就不需要F5调试这么慢了 这个任务也会先运行g++.exe build active file任务然后然后再执行自己的内容

我的大概就是这样了


一些相关链接

发布了43 篇原创文章 · 获赞 0 · 访问量 3527

猜你喜欢

转载自blog.csdn.net/u010571102/article/details/104423438