To use the GCC (g++) C/C++ compiler and GDB debugger from mingw-w64, this tutorial teach you about how to install the MinGW and C/C++ extension for VS Code.
- Install Visual Studio Code: choose "Windows" to download the installer.
- Choose "I accept" and press "Next".
- Set your install path and press "Next".
- Press "Next".
- Tick these two options for "Open with Code" in "Create code file and enjoy it"
- Press "Install".
- After the installation finish, close the window and open the VScode.
- Install the C/C++ extension for VS Code by searching for 'c++' in the Extensions view (
Ctrl+Shift+X).
- Install MinGW - Minimalist GNU for Windows. Please change the directory path to which you can find easily.
- Open MinGW Installation Manager, and mark "mingw32-base" and "mingw32-gcc-g++" for installation.
- Click "Apply Changes" and "Apply".
- Click "Apply".
- Wait for the installation.
- Open your Windows Settings.
- Search "Edit environment variables for your account (編輯您的帳戶的環境變數)".
- Choose the "Path" in user variables, and edit it.
- Open your MinGW directory path which you select above to the system path, and copy the path of the
binfolder.
- Select "New" to add the path of your
binfolder under the MinGW directory path.
- Select "OK" to save the updated path.
- Search "cmd", and open "Command prompt (命令提示字元)".
- Type following command:
gcc --version
g++ --version
gdb --version
- If you don't see the version information or the command is not recognized, please check your "path" of MinGW folder and make sure your installation process correctly.
- You can open your folder and right-click to open with code . (Ref: Step.5 in Install Visual Studio Code and C/C++ extension for VS Code)
- You can create a
.cppfile by click the "New File" , and program your code.
- For C:
#include <stdio.h>
#include <stdlib.h>
int main() {
printf("Hello\n");
return 0;
}
- For C++:
#include <iostream>
using namespace std;
int main() {
cout << "Hello" << endl;
return 0;
}
- Press
Ctrl+Shift+Band select "C/C++: gcc.exe" or "C/C++: g++.exe" to build your code.
- You will find the
.exefile in the workspace.
- Press
Ctrl+Shift+`to open terminal, and type.\FileName.exeto run the executable file.
- Congratulation! You have completed the basic environment construction. If there is a problem with your compilation step, stay tuned for the next tutorial update. ^_−☆
























