Setting up C++ Development Environment

By | May 7, 2023

C++ is programming language. It is object-oriented, and generic programming paradigms. C++ is compatible with multiple platforms such as Windows, Linux, Unix, and Mac.

Using Online IDE

Before starting C++ programming, it is necessary to set up an environment on your local computer to compile and execute C++ programs. You can also use Online Integrated Development Environments (IDEs) to complie and run programs without the need for local setup.

IDE is a software application. It facilitates software development for programmers. These online IDEs streamline the development process. You can write, test, and debug their code efficiently in IDE.

You can also run this code using any Online IDE for C++. You can use this: cpp.sh ide to run below C++ program.

// Using online ide of C++
#include <iostream>
using namespace std;

int main()
{
	cout << "Learning C++ at Cplusplus.in";
	return 0;
}

Setting up a Local Environment:

You need to install two important software to set up a C++ IDE on your local machine:

  1. C++ Compiler
  2. Text Editor

1. C++ Compiler

You need a C++ complier to compile the code. A compiler is a computer program that converts high-level language into machine-understandable low-level language. It convert your code into machine code.

Installing GNU GCC on Linux

You need to follow these steps to install and work with the GCC compiler on Linux:

A. Run these two commands from your Linux terminal window:

sudo apt-get update
sudo apt-get install gcc
sudo apt-get install g++

These commands will install the GCC compiler on your system.

Now, you can run this command:

sudo apt-get install build-essential

It will install all the required libraries. These libraries used to compile and run your C++ program.

B. Check whether GCC compiler is installed correctly. Run this command to verify:

g++ --version

C. You Linux environment is set up and ready to compile C++ programs.

D. Write your program in a text file and save it with any file name and the ‘.cpp’ extension. For example if you have written program to display “Hello World”. Then you can save as “helloworld.cpp” on the desktop.

E. On your Linux terminal and navigate to the directory where you saved your file. Run this command to compile your file:

g++ filename.cpp -o any-name

For example, if you want to compile your above code file, then you need to run this commond on Termnal (after navigating file directory in terminal).

g++ helloworld.cpp -o hello

This command will create executable file in same directory.

F. Now you can run your program by running this command:

./hello

It will execute your code on same terminal.

2. Text Editor

Text editor is a software program which is used to edit or write text files. Generally text files typically have ‘.txt’ extension, but we use ‘.cpp’ or ‘.c’ extension to save C++ files. These files are known as as source code that contain C++ programming language source code. These extensions help the compiler identify the file as a C++ program. You must have a text editor installed for writing programs. Visual Studio Code (VS Code) are one of popular text editor used for C++ programming.

1. Code::Blocks Installation

Code::Blocks is a IDE used for C++ programming language. You need to follow these steps below to install Code::Blocks:

  1. Go to Blocks Setup Packages.
  2. Download the setup package suitable for your operating system.
  3. Locate the downloaded setup file and execute it.
  4. Follow the on-screen instructions to install Code Blocks on your system.
  5. After successfully installing Code::Blocks, open the application.
  6. From the File menu in Code Blocks, select New and choose Empty File.
  7. It will create a new empty file where you can write your C++ program.
  8. Write your C++ program in the empty file.
  9. Save the file with a ‘.cpp’ extension.
  10. Navigate to the Build menu in Code Blocks.
  11. Select the Build and Run option to compile and execute your C++ program.

These are steps to install Code Blocks, create a new C++ program file, and build/run your program using the IDE’s features.

2. Xcode Installation for macOS

If you are a macOS user, you can install Xcode as a code editor for C++ programming.

  1. Go to Apple website or search for Xcode in the Apple App Store. You may follow the link – Xcode for MacOS to download Xcode.
  2. Use instructions provided on the website for installation steps.
  3. After successfully installing Xcode, open the Xcode application.
  4. From the File menu in Xcode, select New, and then choose Project.
  5. It will prompt you to create a new project in Xcode.
  6. In the next window, select the Application option under the OS X section in the left sidebar.
  7. Choose the Command Line Tool option from the available templates and click Next.
  8. Fill in details like name of the organization, product name, etc.
  9. Make sure to choose C++ as the programming language.
  10. Click Next to proceed to the next steps.
  11. Select location where you want to save your project.
  12. From the directory list in the left sidebar, select the main.cpp file.
  13. After opening the main.cpp file, you will see a pre-written C++ program or template.
  14. Modify this program according to your requirements.
  15. Go to the Product menu and choose the Run option from the dropdown.

3. Visual Studio Code Installation on Windows

You need to follow these steps to install Visual Studio Code (VS Code) on Windows:

  1. Go to official Visual Studio Code website and download the appropriate setup file for Windows.
  2. Open and click on “Run”.
  3. Accept the license agreement and click “Next”.
  4. Select (or leave as default) installation location and click “Next”.
  5. Select options and click “Next”.
  6. Click “Install” to begin the installation process.
  7. Once the installation is complete, click “Finish”.
  8. You should now see the Visual Studio Code icon on your desktop.

Download and Install MinGW:

  1. Download MinGW from this link.
  2. Run the installer and choose “Continue”.
  3. Mark all the packages for installation by right-clicking and selecting “Mark for Installation”.
  4. Click “Installation” in top-left corner. Then select “Apply Changes”. This process may take some time to complete.
  5. Now, to Environment Variables, Open “This PC” and navigate to the C drive.
  6. Locate the “MinGW” folder and go to “Bin” inside it.
  7. Copy the path of the “Bin” folder.
  8. Right-click on “This PC” and select “Properties”.
  9. Go to “Advanced System Settings” and click on “Environment Variables”.
  10. In the “System variables” section, locate “PATH” and click “Edit”.
  11. Add a new entry by clicking “New” and paste the copied MinGW Bin path.
  12. Click “OK” to save the changes.
  13. Now to Install Useful Extensions in VS code Open VS code.
  14. Go to the Extensions view by clicking the last icon on the right sidebar.
  15. Install these two extensions: C/C++ and Code Runner
  16. Now to Configure Code Runner to Run in Terminal, Go to “Settings” in Visual Studio Code.
  17. Search for “Terminal” and scroll to the end of the page.
  18. Check the option “[Code-runner: Run In Terminal]”.

These are steps to install VS code on Windows.

4. Visual Studio Code Installation on Mac OS

You need to follow these steps to install Visual Studio Code (VS Code) on Mac OS

  1. Go to official Visual Studio Code website and download the installation package for Mac OS.
  2. Open the downloaded package.
  3. Follow the on-screen instructions.

Install Homebrew:

  1. Open Terminal by pressing Cmd + Space and typing “Terminal”.
  2. In the Terminal, copy and paste the following command:
    arch -x86_64 ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install)" < /dev/null 2> /dev/null
    
  3. Hit Enter to execute above command. Installation process may take some time.

Install MinGW Compiler:

  1. Open Terminal and run this command:
    arch -x86_64 brew install MinGW-w64
    
  2. Installation process may take some time.
  3. Now you can Install Useful Extensions in Visual Studio Code, so Open VS Code.
  4. Go to the Extensions view by clicking the last icon on the right sidebar.
  5. Install these two extensions: C/C++ and Code Runner
  6. To Configure Code Runner to Run in Terminal: Go to “Settings” in VS Code.
  7. Search for “Terminal” and scroll to the end of the page.
  8. Check the option “[Code-runner: Run In Terminal]”.

So these are steps to install Visual Studio Code for C++ programming on Mac OS.

Author: Mithlesh Upadhyay

I hold an M.Tech degree in Artificial Intelligence (2023) from Delhi Technological University (DTU) and possess over 4 years of experience. I worked at GeeksforGeeks, leading teams and managing content, including GATE CS, Test Series, Placements, C, and C++. I've also contributed technical content to companies like MarsDev, Tutorialspoint, StudyTonight, TutorialCup, and Guru99. My skill set includes coding, Data Structures and Algorithms (DSA), and Object-Oriented Programming (OOPs). I'm proficient in C++, Python, JavaScript, HTML, CSS, Bootstrap, React.js, Node.js, MongoDB, Django, and Data Science.