安装C语言运行环境
百度云盘:https://pan.baidu.com/s/1CWqcUz2-T8p3bOOX6pHh5g
提取码:kp8t
下载.NET Framework 4.7.2: https://dotnet.microsoft.com/download
安装VS CODE
安装插件
- Cpptools
- C/C++(就是有些教程里的cpptools)
- C/C++ Snippets(Snippets即重用代码块)
- C/C++ Advanced Lint(vscode-c-cpp-flylint)(Lint即静态检测)
- Code Runner
- Include Autocomplete
安装mingw-get
windows下调试仅支持 Cygwin 和 MinGW。
安装以下拓展包
- All Packages/MinGW/Mingw32-gcc bin
- All Packages/MinGW /Mingw32-gcc-g++ bin
- All Packages/MinGW/MinGW Base System/Mingw32-gdb bin
选中几个需要的项右键Make for Installation进行标记,其中gcc和g++为c和c++编译器
选择完全部想要安装的项后点击左上角Installation菜单下的Apply Changes应用修改
配置系统环境变量path
控制面板\所有控制面板项\系统\系统设置\环境变量\系统变量\path
添加“;D:\MinGW\bin” // MinGw安装路径
配置vscode
- 新建文件夹(d:\LYH20190317002)
- 新建文件study.c
- 添加断点
- 点击调试,跳出跳出一个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", "type": "cppdbg", "request": "launch", "program": "${workspaceRoot}/${fileBasenameNoExtension}.exe", // enter program name, for example ${workspaceFolder}/a.exe "args": [], "stopAtEntry": false, "cwd": "${workspaceRoot}", // ${workspaceFolder} "environment": [], "externalConsole": true, "MIMode": "gdb", "miDebuggerPath": "D:\\MinGW\\bin\\gdb.exe", "preLaunchTask": "gcc", "setupCommands": [ { "description": "Enable pretty-printing for gdb", "text": "-enable-pretty-printing", "ignoreFailures": true } ] } ] }
- program一项,指明了需要运行的文件
- miDebuggerPath是我们安装gdb的路径,调试的二进制文件(可执行二进制文件也叫命令)
- preLauchTask配置的意思是用gdb去调试 program参数指定的二进制文件
- 在.vscode文件夹下新建tasks.json文件
{ "version": "2.0.0", "command": "gcc", "args": ["-g","${file}","-o","${fileBasenameNoExtension}.exe"] }
调试:F5
手动编译
- 新建文件:
#include <stdio.h>
int main()
{
int n;
printf("This is a test file!\r\nInput a number: ");
scanf("%d",&n);
printf("The number is %d",n);
return 0;
}
- 编译
> gcc -g study_1.c -o study.exe
- 执行
>.\study.exe
参考