C/C++ Compiler Installation Guide for VSCode
VSCode does not include a compiler or debugger, so you need to install one separately. Follow the steps below based on your operating system.
Windows
Recommended Compilers
- MinGW (Minimalist GNU for Windows)
- Microsoft Visual C++ (Optional, more complex setup)
Installation Instructions for MinGW
-
Download MinGW:
- Visit MinGW on SourceForge.
- Download the installer (
mingw-get-setup.exe).
-
Install MinGW:
- Run the installer and follow the prompts.
- In the MinGW Installation Manager, select:
mingw32-gcc-g++(for C++ compiler)mingw32-base(for C compiler)
- Click Installation in the top-left menu, then select Apply Changes.
- Wait for the installation to complete.
-
Set Up Environment Variable (Path):
- The environment variable tells Windows where to find the MinGW compiler. This step is critical and can be tricky for beginners, so follow these detailed instructions:
- Open Environment Variables:
- Search for Environment variable (System)
- Click Environment Variables on bottom section.
- Locate the Path Variable:
- In the User Variables section (upper half), look for a variable named
Path. - If you don’t see
Path, click New to create it. - If
Pathexists, select it and click Edit.
- In the User Variables section (upper half), look for a variable named
- Add MinGW Path:
- By default, MinGW installs to
C:\MinGW. The compiler tools are in thebinfolder (e.g.,C:\MinGW\bin). - In the Edit Environment Variable window, click New and paste the path to the
binfolder (e.g.,C:\MinGW\bin). - If MinGW was installed elsewhere, find the
binfolder in your installation directory and use that path. - Click OK to close each window.
- By default, MinGW installs to
- Open Environment Variables:
- The environment variable tells Windows where to find the MinGW compiler. This step is critical and can be tricky for beginners, so follow these detailed instructions:
-
Verify Compiler Installation:
- Open a Command Prompt.
- Type
gcc --versionand press Enter. - If installed correctly, you’ll see the GCC version (e.g.,
gcc (MinGW.org GCC-8.2.0-3) 8.2.0). - If you get an error like
'gcc' is not recognized, the Path variable is likely incorrect. Revisit step 3.
MacOS
Recommended Compiler
- Clang (included with Xcode Command Line Tools)
Installation Instructions
- Install Xcode Command Line Tools:
- Open the Terminal (search for it using Spotlight or find it in Applications > Utilities).
- Type
xcode-select --installand press Enter. - Follow the prompts to install the tools (this includes Clang).
-
Verify Compiler Installation:
- In the Terminal, type
clang --versionand press Enter. - If installed correctly, you’ll see the Clang version (e.g.,
Apple clang version 14.0.0).
- In the Terminal, type
-
Note: GCC is also installed alongside clang so you can also try
gcc --versionand press enter to check it.
Linux
Recommended Compilers
- GCC (GNU Compiler Collection)
- Clang (alternative)
Installation Instructions
- Install GCC:
- Open a terminal.
- For Debian/Ubuntu:
- Run
sudo apt updateto update package lists. - Run
sudo apt install gcc g++to install GCC and G++.
- Run
- For Fedora:
- Run
sudo dnf install gcc g++.
- Run
- Verify Compiler Installation:
- Type
gcc --versionorclang --versionin the terminal and press Enter. - If installed, you’ll see the compiler version (e.g.,
gcc (Ubuntu 9.4.0-1ubuntu1) 9.4.0).
- Type
Troubleshooting Tips
- Command not found (Windows): Ensure the MinGW
binfolder is correctly added to the Path variable. Restart your Command Prompt or computer after setting the Path. - macOS installation issues: If
xcode-select --installfails, try installing Xcode from the App Store, then run the command again. - Linux package errors: Ensure your package manager is updated (
sudo apt updateorsudo dnf update) before installing.