首页 > 编程语言 > 详细

VS Code编译C/C++

时间:2020-03-25 15:48:25      阅读:51      评论:0      收藏:0      [点我收藏+]

如何让VSCode做C++开发的IDE?

1.安装MINGW, 配置PATH

技术分享图片

编译器安装成功

技术分享图片

2.安装VS 插件

技术分享图片

在terminal调试下

技术分享图片

3.配置 launch.json, 项目根目录\.vscode下。复制进去之后要修改miDebuggerPath参数,这里面填写自己的gdb.exe路径,编译配置已完成。

{
    // 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": "${file}.exe",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceRoot}",
            "environment": [],
            "externalConsole": true,
            "MIMode": "gdb",
            "miDebuggerPath": "C:\\MinGW\\bin\\gdb.exe",
            "preLaunchTask": "g++",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ]
        }
    ]
}

4.Ctrl+Shift+P,输入Tasks:Configure Task,之后选择使用模板创建tasks.json文件, 同样保存在根目录\.vscode下  

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "command": "g++",
    "args": ["-g","${file}","-o","${file}.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
        }
    }
}

  

5. 按F5即可执行,如果console控制台只闪出来一下,不能观察到结果,解决办法是在return 0之前增加一句system("pause"),缺点在于每个文件都要写,不知道有没有更好的办法。

技术分享图片

 

参考: https://blog.csdn.net/qq_39630587/article/details/79826652

   https://www.zhihu.com/question/30315894 

VS Code编译C/C++

原文:https://www.cnblogs.com/7star/p/12566246.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!