vscode mingw gcc
时间: 2023-10-29 10:00:08 浏览: 111
Using GCC with MinGW for VSCode(VSCode 配置开发 C++)
To use VSCode with MinGW and GCC, you will need to follow these steps:
1. Install MinGW-w64: This is a compiler suite for Windows that includes the GCC compiler. Download and install MinGW-w64 from the official website.
2. Configure VSCode: Open VSCode and go to the Extensions tab. Search for "C/C++" and install the extension provided by Microsoft. This extension will provide language support and debugging capabilities for C/C++.
3. Set up the build task: Press `Ctrl + Shift + B` to open the task runner in VSCode. Select "Create tasks.json file from template" and choose "Others" as the template. In the generated tasks.json file, replace the content with the following:
```
{
"version": "2.0.0",
"tasks": [
{
"label": "Build",
"type": "shell",
"command": "gcc",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"group": {
"kind": "build",
"isDefault": true
},
"presentation": {
"echo": true,
"reveal": "always",
"focus": false,
"panel": "shared"
}
}
]
}
```
4. Create a new C file: Create a new file in VSCode and paste the following code:
```c
#include <stdio.h>
int main() {
printf("Hello, world!");
return 0;
}
```
5. Build and run the code: Press `Ctrl + Shift + B` again to build the code. This will compile the C code using GCC. After the build is successful, you can run the code by opening the integrated terminal in VSCode (View -> Terminal) and executing the generated executable file.
Please note that these steps assume you have already installed MinGW-w64 and have properly configured VSCode.
阅读全文