vscode配置c

1:下载mingw64的链接

https://sourceforge.net/projects/mingw-w64/files/

下载这个:x86_64-win32-sjlj
之后添加到环境变量path中,(文件名到bin为止)

2:ctrl+shift+p,选择c/c++ UI,对“指定编译器路径或从下拉列表中选择检测到的编译器路径”和“IntelliSense 模式”进行修改

改为“D:/mingw/mingw64/bin/g++.exe”和“gcc-x86"

3:在.vscode中创建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",
            "preLaunchTask": "g++.exe build active file",//调试前执行的任务,就是之前配置的tasks.json中的label字段
            "type": "cppdbg",//配置类型,只能为cppdbg
            "request": "launch",//请求配置类型,可以为launch(启动)或attach(附加)
            "program": "${fileDirname}\\${fileBasenameNoExtension}.exe",//调试程序的路径名称
            "args": [],//调试传递参数
            "stopAtEntry": true,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": true,//true显示外置的控制台窗口,false显示内置终端
            "MIMode": "gdb",
            "miDebuggerPath": "D:/mingw/mingw64/bin/gdb.exe",//按照c_cpp_properties.json中的路径自行修改,不过g++要改成gdb
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ]
        }
    ]
}`

另外创建tasks.json

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558 
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
        {
            "type": "shell",
            "label": "g++.exe build active file",//任务的名字,就是刚才在命令面板中选择的时候所看到的,可以自己设置
            "command": "D:/mingw/mingw64/bin/g++.exe",
            "args": [//编译时候的参数
                "-g",//添加gdb调试选项
                "${file}",
                "-o",//指定生成可执行文件的名称
                "${fileDirname}\\${fileBasenameNoExtension}.exe"
            ],
            "options": {
                "cwd": "D:/mingw/mingw64/bin"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true//表示快捷键Ctrl+Shift+B可以运行该任务
            }
        }
    ]
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
1. 安装VS Code(如果没有安装的话)。 2. 安装C/C++插件。在VS Code中,打开Extensions面板(快捷键为Ctrl+Shift+X),搜索C/C++插件,安装即可。 3. 安装C编译器。在Windows系统中,可以安装MinGW,MacOS中可以安装Xcode Command Line Tools,Linux中可以通过apt-get或yum等包管理器安装gcc。 4. 配置VS Code的tasks.json文件。在VS Code中,使用快捷键Ctrl+Shift+P打开命令面板,输入“Tasks: Configure Task”,选择“Create tasks.json file from template”创建tasks.json文件。在该文件中输入以下内容: { "version": "2.0.0", "tasks": [ { "label": "build", "type": "shell", "command": "gcc", "args": [ "-g", "${file}", "-o", "${fileDirname}/${fileBasenameNoExtension}" ], "group": { "kind": "build", "isDefault": true } } ] } 5. 配置VS Code的launch.json文件。在VS Code中,使用快捷键Ctrl+Shift+P打开命令面板,输入“Debug: Open launch.json”,选择“C++ (GDB/LLDB)”并保存。在该文件中输入以下内容: { "version": "0.2.0", "configurations": [ { "name": "C++ Launch (GDB)", "type": "cppdbg", "request": "launch", "program": "${fileDirname}/${fileBasenameNoExtension}", "args": [], "stopAtEntry": false, "cwd": "${workspaceFolder}", "environment": [], "externalConsole": true, "MIMode": "gdb", "miDebuggerPath": "/usr/bin/gdb" } ] } 6. 编写C程序。在VS Code中,新建一个C程序,编写好代码并保存。 7. 编译程序。使用快捷键Ctrl+Shift+B,选择“build”任务,按Enter键即可编译程序。 8. 调试程序。使用快捷键F5,选择“C++ Launch (GDB)”配置,按Enter键即可开始调试程序。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值