vscode怎么调试c语言程序,vscode运行c语言代码

首页 > 经验 > 作者:YD1662022-11-14 05:05:33

VSCode只是一个编写代码的辅助工具,支持所有主流的开发语言,但是每一种语言的编译器,调试器是不一样的,而VSCode本身也不带这些编译调试工具。因此,想要在VSCode里开发调试程序,必须配套安装相应语言的编译工具。下面以C语言开发为例给大家介绍(具体操作可参考我的视频)

Task编译配置

从Terminal>Configure Task...进入,需要将“command”指定为你电脑上minGW的路径;"Label"值根据自己喜好设定。

{ "version": "2.0.0", "tasks": [ { "type": "shell", "label": "myGccTask", "command": "E:\\Program files (x86)\\mingw-w64\\i686-8.1.0-posix-dwarf-rt_v6-rev0\\mingw32\\bin\\gcc.exe", "args": [ "-g", "${file}", "-o", "${fileDirname}\\${fileBasenameNoExtension}.exe" ], "options": { "cwd": "${workspaceFolder}" }, "problemMatcher": [ "$gcc" ], "group": { "kind": "build", "isDefault": true } } ] }全局编译器路径设定

从左下角Manage>Setting>extensions>C/C , edit insetting.json

同样需要修改"C_Cpp.default.compilerPath"的路径。

{ "C_Cpp.updateChannel": "Insiders", "cStandard": "c11", "intelliSenseMode": "gcc-x64", "C_Cpp.default.compilerPath": "E:\\Program Files (x86)\\mingw-w64\\i686-8.1.0-posix-dwarf-rt_v6-rev0\\mingw32\\bin\\gcc.exe", "C_Cpp.commentContinuationPatterns": [ "/**" ], "git.autofetch": true, "git.path": "E:\\Program Files\\Git\\bin\\git.exe", "terminal.integrated.shell.windows": "C:\\Windows\\System32\\cmd.exe", }调试功能配置

从Run>Open configurans进入,同样要修改“miDebuggerPath”的值。

注意:"preLaunchTask"的值要与Task中的“label”的值一致。

{ "version": "0.2.0", "configurations": [ { "name": "gcc my", "type": "cppdbg", "request": "launch", "program": "${fileDirname}\\${fileBasenameNoExtension}.exe", "args": [], "stopAtEntry": false, "cwd": "${workspaceFolder}", "environment": [], "externalConsole": false, "MIMode": "gdb", "miDebuggerPath": "E:/Program Files (x86)/mingw-w64/i686-8.1.0-posix-dwarf-rt_v6-rev0/mingw32/bin/gdb.exe", "setupCommands": [ { "description": "Enable pretty-printing for gdb", "text": "-enable-pretty-printing", "ignoreFailures": true } ], "preLaunchTask": "myGccTask" } ] }Git路径的配置

具体操作参见视频,参数参考本文02中“git.path”。

栏目热文

文档排行

本站推荐

Copyright © 2018 - 2021 www.yd166.com., All Rights Reserved.