How to install C Compiler?
If you’re looking to start programming in C or C++, you’ll need a good compiler and a code editor. In this guide, we’ll walk you through the process of installing the MinGW compiler from the SourceForge website and setting up Visual Studio Code (VS Code) as your code editor. Let’s get started!
What You Will Need
- A Windows computer
- Internet connection
Step 1: Download MinGW Compiler
1.1 Go to the SourceForge Website
- Open your web browser.
- Go to the MinGW SourceForge page.
1.2 Download the Installer
- On the MinGW page, click on the Download button. This will download a file named
mingw-get-setup.exe
to your computer.
1.3 Run the Installer
- Locate the downloaded
mingw-get-setup.exe
file and double-click on it to run the installer. - Click Install to start the installation process.
- Follow the on-screen instructions. Make sure to install it in a directory without spaces in the path (e.g.,
C:\MinGW
).
1.4 Select Components
- After installation, a window called MinGW Installation Manager will open.
- Select the following packages:
mingw32-base
mingw32-gcc-g++
mingw32-msys-base
- To select them, right-click on each package and choose Mark for Installation.
1.5 Apply Changes
- After selecting the packages, click on Installation in the menu bar.
- Select Apply Changes. This will download and install the selected packages.
1.6 Set Environment Variables
- Right-click on This PC or My Computer on your desktop or in File Explorer, and select Properties.
- Click on Advanced system settings on the left side.
- In the System Properties window, click the Environment Variables button.
- Under the System variables section, find the
Path
variable and select it, then click on Edit. - Click on New and add the path to the MinGW
bin
directory, usuallyC:\MinGW\bin
. - Click OK to close all dialog boxes.
1.7 Verify the Installation
- Open the Command Prompt by typing
cmd
in the Windows search bar and pressing Enter. - Type
gcc --version
and press Enter. - You should see the version of the GCC compiler installed, confirming that MinGW is correctly installed.
Step 2: Install Visual Studio Code (VS Code)
2.1 Download Visual Studio Code
- Open your web browser.
- Go to the Visual Studio Code website.
- Click on the Download for Windows button.
2.2 Run the Installer
- Once the download is complete, locate the
VSCodeSetup.exe
file and double-click on it. - Click Next to start the installation process.
- Accept the agreement and click Next.
2.3 Select Installation Location
- Choose the destination folder where you want to install VS Code or leave it as default and click Next.
2.4 Select Additional Tasks
- In this step, you can choose additional tasks like creating a desktop icon or adding to PATH. Select the options you want and click Next.
2.5 Install VS Code
- Click Install to begin the installation.
- Once the installation is complete, you can check the box to launch VS Code and click Finish.
Step 3: Set Up C/C++ Extension in VS Code
3.1 Open Visual Studio Code
- Launch Visual Studio Code.
3.2 Install the C/C++ Extension
- Click on the Extensions icon in the left sidebar (it looks like four squares).
- In the search bar, type
C/C++
and find the extension provided by Microsoft. - Click Install to add the C/C++ extension to VS Code.
- Search for the Code Runner extension and install it as well.
- Close the Extensions tab.
- Click on the Explorer icon in the left sidebar to open the file explorer.
- Click on the New File icon to create a new file and save it with a
.c
extension (e.g.,hello.c
). - Write a simple C program in the file, such as:
3.3 Build and Run the Program
- Click on the Run/Play icon in the top right corner of the editor.
- Click on Run Code to compile and run the program.
- You should see the output
Hello, World!
in the terminal at the bottom of the VS Code window. Now you can build and run your program directly from VS Code!
Conclusion
Congratulations! You have successfully installed the MinGW compiler from SourceForge and set up Visual Studio Code for C/C++ programming. You’re now ready to start coding and creating your own programs. Happy coding!