说明:此文章是我完全转载的,我只是完全拷贝过来作为备份文章,方便查看。 在此感谢原作者,原作者文章地址:https://blog.csdn.net/qq_43067190/article/details/82117149 环境: WIN10 64 专业版 vscode版本:1.24.1 launch.json版本:0.2.0 tasks.json版本:2.0.0 mingw-w64版本:8.1.0 配置过程: 一、 安装vscode vscode官网下载安装包直接安装即可 二、 vscode内安装C/C++ 插件 vscode内按快捷组合键Ctrl+Shift+X(或如图点击[拓展]按钮)打开拓展分页,在搜索栏输入” C “,查找到如图的第一个插件,安装并重新加载之。再推荐几个插件,包括彩虹括号和汉化。




三、 安装mingw-w64(具体安装与环境变量配置可以查看这里) 在mingw-w64官网下载64位的mingw-w64离线包 https:///projects/mingw-w64/files/?source=navbar 根据系统选择合适的安装包进行下载(win10_64位选择如图标签) 
下载完成后出现安装包 安装该包,在Setting 界面将Architecture选项改为x86_64,其他不变,选择合适的安装路径(默认或重新指定都可以,路径中不要有中文) 也可以直接下载文件压缩包(我是下载文件压缩包直接解压就可以用了) 

配置计算机环境变量如图(我的解压路径是C:\Program Files\mingw-w64\x86_64-8.1.0-release-posix-sjlj-rt_v6-rev0,因此环境变量这么加)
 安装完成后打开控制台,分别输入 g++ -v 和 gcc -v、gdb -v 查看环境是否安装成功(是否有当前版本号) 

四、重启电脑(重要)。 五、配置运行环境 打开vscode,选择或新建一个空文件夹目录打开作为项目目录。 点击“文件”按钮,再点击“新建文件夹”按钮,并重命名为”.vscode”。 在该文件夹内,在点击“新建文件”按钮,建launch.json,settings.json,tasks.json三个.json文件。如图所示。
 launch.json的文件内容如下: "preLaunchTask": "build", "program": "${fileDirname}/${fileBasenameNoExtension}.exe", "cwd": "${workspaceFolder}", "miDebuggerPath": "C:/Program Files/mingw-w64/x86_64-8.1.0-release-posix-sjlj-rt_v6-rev0/mingw64/bin/gdb.exe", // 这里修改GDB路径为安装的mingw64的bin下的gdb.exe路径 "description": "Enable pretty-printing for gdb", "text": "-enable-pretty-printing",
tasks.json的文件内容如下: "\"${fileDirname}\\${fileBasenameNoExtension}.exe\"", "-finput-charset=UTF-8",//输入编译器文本编码 默认为UTF-8 "-fexec-charset=GBK"//编译器输出文本编码 自行选择
settings.json的文件内容如下: 用户设置为: // Configuring tasks.json for C/C++ debugging // repo: https://gist.github.com/huihut/887d3c28db92617bd5148c20a5ff112a // Available variables which can be used inside of strings. // ${workspaceRoot}: the root folder of the team // ${file}: the current opened file // ${fileBasename}: the current opened file's basename // ${fileDirname}: the current opened file's dirname // ${fileExtname}: the current opened file's extension // ${cwd}: the current working directory of the spawned process "\"${fileDirname}\\${fileBasenameNoExtension}.exe\"" "files.autoSave": "afterDelay", "files.encoding": "utf8", "files.autoGuessEncoding": true, "explorer.confirmDragAndDrop": false, "workbench.colorTheme": "Visual Studio Dark", "team.showWelcomeMessage": false
工作区设置: "C_Cpp.errorSquiggles": "Disabled",
至此,环境配置完成。 六、运行C代码 新建helloworld.c文件,键入或粘贴C语言的helloworld代码,按F5调试运行。 printf("hello world!\n\n");

代码中system(“pause”);语句是“请按任意键继续….”,没有此句,调试窗口将一闪就退出。
|