Start Programming in C++: Step-by-Step Tutorial with MinGW and Dev-C++ on Windows
Do you want to learn C++ programming easily and without complications? You are in the right place! In this step-by-step tutorial, we will teach you how to set up your development environment on Windows using MSYS2, MinGW, and Dev-C++. By the end of this guide, you will be ready to write your first C++ programs and take the first step in your journey as a programmer.
This article is perfect for beginners seeking a clear and practical introduction to C++ programming. Follow each step and turn your PC into a tool ready to develop amazing projects.
Learning Objectives
At the end of this lesson, the student will be able to:
- Set up a development environment on Windows using MSYS2, MinGW, and Dev-C++.
- Install the MinGW compiler and verify its functionality through terminal commands.
- Configure environment variables to ensure the compiler works correctly.
- Download and install Dev-C++ as an integrated development environment (IDE).
- Create a basic console project in Dev-C++ and properly associate it with the installed compiler.
- Write a basic C++ program that prints a message to the console.
- Compile and run a program in Dev-C++, ensuring processes are correctly configured.
CONTENT INDEX
Installing MSYS2 and Configuring MinGW
Installing Dev-C++
Setting Up and Creating a Basic Program
Quick Tips
Installing MSYS2 and Configuring MinGW
In this tutorial, we will use MSYS2 as the environment to install and configure the MinGW compiler.
Downloading and Installing MSYS2
- Visit the official MSYS2 website: https://www.msys2.org/.
- Download the appropriate installer for your operating system.
- Run the installer and follow the instructions to install MSYS2.
Updating the MSYS2 Environment
- Open the MSYS2 terminal.
- Type the following command to update the system:
pacman -Syu
- Close and reopen the terminal to complete the update process.
Installing the gcc Compiler
- In the MSYS2 terminal, install the required packages for MinGW:
pacman -S mingw-w64-x86_64-gcc
- This will install the 64-bit GCC compiler.
Setting the PATH Environment Variable
- Find the folder where MinGW was installed within MSYS2. By default, it should be:
C:\msys64\mingw64\bin
- Add this folder to the system’s environment variables:
- Open the start menu and search for Environment Variables Configuration.
- In the window that appears, click on Environment Variables.
- In the System Variables section, select the
Pathvariable and click Edit. - Click New and add:
C:\msys64\mingw64\bin
- Save the changes and close all windows.
Verifying the Installation
- Open a CMD terminal.
- Type the command:
g++ --version
- You should see the version of the installed GCC compiler.
Installing Dev-C++
Downloading Dev-C++
- Go to the official Orwell Dev-C++ website: https://sourceforge.net/projects/orwelldevcpp/.
- Download the latest version.
Installing Dev-C++
- Run the installer and follow the instructions.
- Choose a theme and initial configuration according to your preference.
Setting Up and Creating a Basic Program
Configuring the Compiler in Dev-C++
- Open Dev-C++.
- Go to Tools > Compiler Options.
- Ensure that the compiler path is:
C:\msys64\mingw64\bin
Creating a Project
- Go to File > New > Project.
- Select Console and C++.
- Enter a name for your project and save it in a folder.
Writing the Code
Write the following code in the main file:
#include <iostream>
using namespace std;
int main() {
cout << "Hello, world!" << endl;
return 0;
}
Compiling and Running
- Save the file as
main.cpp. - Click on Compile and Run or press
F11. - A console will appear displaying the message:
Hello, world!.
Quick Tips
- If Dev-C++ cannot find the compiler, verify that
C:\msys64\mingw64\binis included in both the compiler settings and thePathenvironment variable. - You can now start modifying the basic code to practice with variables, loops, functions, or anything you can imagine.
If everything worked as expected, you should now be ready to start programming in C++ using Dev-C++ with MSYS2. Good luck!
