The Wayback Machine - https://web.archive.org/web/20240917171308/https://www.geeksforgeeks.org/setting-c-development-environment/
Open In App

Setting up C++ Development Environment

Last Updated : 30 Jun, 2023
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

C++ is a general-purpose programming language and is widely used nowadays for competitive programming. It has imperative, object-oriented, and generic programming features. 
C++ runs on lots of platforms like Windows, Linux, Unix, Mac, etc. Before we start programming with C++. We will need an environment to be set up on our local computer to compile and run our C++ programs successfully. If you do not want to set up a local environment you can also use online IDEs for compiling your program.

Using Online IDE

IDE stands for an integrated development environment. IDE is a software application that provides facilities to a computer programmer for developing software. There are many online IDEs available that you can use to compile and run your programs easily without setting up a local development environment. The

ide.geeksforgeeks.org is one such IDE provided by GeeksforGeeks. 

 

You can click on the Run on IDE button to run the program.

C++




// Using online ide of C++
#include <iostream>
using namespace std;
 
int main()
{
    cout << "Learning C++ at GeekforGeeks";
    return 0;
}


Output

Learning C++ at GeekforGeeks

Time Complexity: O(1)
Auxiliary Space: O(1)
 

Setting up a Local Environment

For setting up a C++ Integrated Development Environment (IDE) on your local machine you need to install two important software:

  1. C++ Compiler
  2. Text Editor

1. C++ Compiler

Once you have installed the text editor and saved your program in a file with the ‘.cpp’ extension, you will need a C++ compiler to compile this file. A compiler is a computer program that converts high-level language into machine-understandable low-level language. In other words, we can say that it converts the source code written in a programming language into another computer language that the computer understands. For compiling a C++ program we will need a C++ compiler that will convert the source code written in C++ into machine codes. Below are the details about setting up compilers on different platforms.

Installing GNU GCC on Linux

We will install the GNU GCC compiler on Linux. To install and work with the GCC compiler on your Linux machine, proceed according to the below steps: 

A. You have to first run the below two commands from your Linux terminal window: 

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

B. This command will install the GCC compiler on your system. You may also run the below command:

sudo apt-get install build-essential

This command will install all the libraries which are required to compile and run a C++ program.
 
C. After completing the above step, you should check whether the GCC compiler is installed in your system correctly or not. To do this you have to run the below-given command from the Linux terminal:

g++ --version

D. If you have completed the above two steps without any errors, then your Linux environment is set up and ready to be used to compile C++ programs. In further steps, we will learn how to compile and run a C++ program on Linux using the GCC compiler. 
 
E. Write your program in a text file and save it with any file name and.CPP extension. We have written a program to display “Hello World” and saved it in a file with the filename “helloworld.cpp” on the desktop. 
 
F. Now you have to open the Linux terminal and move to the directory where you have saved your file. Then you have to run the below command to compile your file: 

g++ filename.cpp -o any-name

G. filename.cpp is the name of your source code file. In our case, the name is “helloworld.cpp” and any-name can be any name of your choice. This name will be assigned to the executable file which is created by the compiler after compilation. In our case, we choose any-name to be “hello”. 
We will run the above command as: 

g++ helloworld.cpp -o hello

H. After executing the above command, you will see a new file is created automatically in the same directory where you have saved the source file and the name of this file is the name you chose as any-name. 
Now to run your program you have to run the below command: 

./hello

I. This command will run your program in the terminal windows.

2. Text Editor

Text Editors are the type of programs used to edit or write texts. We will use text editors to type our C++ programs. The normal extension of a text file is (.txt) but a text file containing a C++ program should be saved with a ‘.cpp’ or ‘.c’ extension. Files ending with the extension ‘.CPP’ and ‘.C’ are called source code files and they are supposed to contain source code written in C++ programming language. These extension helps the compiler to identify that the file contains a C++ program. 
Before beginning programming with C++, one must have a text editor installed to write programs. Follow the below instructions to install popular code editors like VS Code and Code::Block on different Operating Systems like windows, Mac OS, etc.

1. Code::Blocks Installation

There are lots of IDE available that you can use to work easily with the C++ programming language. One of the popular IDE is Code::Blocks.

  • To download Code::Blocks, select the setup package based on your OS from this link – Code::Blocks Setup Packages.
  • Once you have downloaded the setup file of Code::Blocks from the given link open it and follow the instruction to install.
  • After successfully installing Code::Blocks, go to File menu -> Select New and create an Empty file.
  • Now write your C++ program in this empty file and save the file with a ‘.cpp’ extension.
  • After saving the file with the ‘.cpp’ extension, go to the Build menu and choose the Build and Run option.

2. XCode Mac OS X Installation

If you are a Mac user, you can download Xcode as a code editor.

  • To download Xcode you have to visit the apple website or you can search for it on the apple app store. You may follow the link – Xcode for MacOS to download Xcode. You will find all the necessary installation instructions there.
  • After successfully installing Xcode, open the Xcode application. 
  • To create a new project. Go to File menu -> select New -> select Project. This will create a new project for you. 
  • Now in the next window, you have to choose a template for your project. To choose a C++ template choose the Application option which is under the OS X section on the left sidebar. Now choose command-line tools from available options and hit the Next button. 
  • On the next window provide all the necessary details like ‘name of organization’, ‘Product Name, etc. But make sure to choose the language as C++. After filling in the details hit the next button to proceed to further steps. 
  • Choose the location where you want to save your project. After this choose the main.cpp file from the directory list on the left sidebar.
  • Now after opening the main.cpp file, you will see a pre-written c++ program or template provided. You may change this program as per your requirement. To run your C++ program you have to go to the Product menu and choose the Run option from the dropdown.

Another very easy-to-use and most popular IDE nowadays, is VSC( Visual Studio Code), for both Windows and Mac OS.

3. Installing VS Code on Windows

Start with installing Visual Studio Code as per your windows. Open the downloaded file and click Run -> (Accept the agreement) Next -> Next -> Next -> (check all the options) -> Next ->Install->Finish. 
Now you’ll be able to see the Visual Studio Code icon on your desktop.

  • Download the MinGW from the link.
  • After Install, “Continue”. Check all the Packages (Right Click -> Mark for Installation). Now, Click on Installation (left corner) -> Apply Changes. (This may take time)
  • Open This PC -> C Drive -> MinGW -> Bin. (Copy this path)
  • Right, Click on “This PC” -> Properties -> Advanced System Setting -> Environment variables ->  (Select PATH in System variables) -> Edit -> New -> Paste the path here and OK.
  • Go to Visual Studio Code, and Install some useful extensions (from the right sidebar, last icon(probably))-
    • C/C++
    • Code Runner
  •  Now, Go to Setting -> Settings -> Search for Terminal -> Go to the end of this page -> Check [ Code-runner: Run In Terminal ]

Yay!  You are good to go now. Open any folder, create new files and Save them with the extension “.cpp”. 

4. Installing VS Code on Mac OS

First of all, Install Visual Studio Code for Mac OS using this link. Then We’ll install the compiler MinGW. For this, we first need to install Homebrew.

To install Homebrew, Open Terminal (cmd + space). Write Terminal and hit Enter. In cmd copy the given command 

arch -x86_64 ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install)" < /dev/null 2> /dev/null

This will download and install HomeBrew on your Mac system. This process may take time.

Now We’ll install the MinGW compiler on Mac OS. Paste the given command in the terminal and press Enter.

arch -x86_64 brew install MinGW-w64
  • This is also time taking process so be patient!     
  • Go to Visual Studio Code, and Install some useful extensions (from the right sidebar, last icon(probably))-
    • C/C++
    • Code Runner
  • Now, Go to Setting -> Settings -> Search for Terminal -> Go to the end of this page -> Check [ Code-runner:  Run In Terminal ]

Yay! You are good to go now. Now open any folder, create new files, and Save them with the extension “.cpp”. 

 



Previous Article
Next Article

Similar Reads

Setting up Java Competitive Programming Environment
An operating system is required to be installed on your system. here we will be discussing the setup in windows. However, you can choose any operating system. Install JDK (Java Development Kit) JDK, is a program that allows you to write Java code from the comfort of your desktop. It contains a variety of tools that are very useful for creating, run
5 min read
Program to show that Linux provides time sharing environment to processes
Time-sharing means sharing of computing resources among many users (processes) by means of multiprogramming and multitasking. By allowing a large number of users to interact concurrently, time-sharing dramatically lowered the cost of providing computing capability. Many operating system including Windows, Linux and many others provides time-sharing
2 min read
10 Myths About Software Development
There are many myths and false assumptions that continue to loom around software development. Even though the first programming language, Fortran, was created in 1957 and the World Wide Web has eclipsed the quarter-century mark, software development is still viewed as some sort of dark magic, thus making people hesitant to embrace new technology. T
5 min read
Introduction to Xamarin | A Software for Mobile App Development and App Creation
The entire world is now surrounded by billions and trillions of mobile Tech which is inevitable. The major share of the development of mobile apps is taken by the Google's Android, Apple's iOS, and Microsoft's Windows. Every new learner or newbie in Mobile Development Domain finds himself in the dilemma of choosing the platform to start with. They
9 min read
Cadence interview Experience | Software Development Engineer
CADENCE: OFFICE INTERVIEWS Round-1 Online Test: Section 1: 20 Aptitude MCQs for 20 Min Section 2: 10 Technical MCQ for 10 Min Section 3: Coding: 60 Minutes 1. Reverse a Linked list 2. Check Balanced Parentheses 3. Given chess Board size print squares of each size present in chess board 4. Given a text file status.txt representing transition of stat
4 min read
12 Web Development Checklists Every Team Should Keep Handy
A website when build should be attractive, meet the goals of businesses, and be easy to handle. There are various factors that help in keeping it successful. A comprehensive web development checklist can help in delivering a better final product. A checklist is a list that keeps track of items required in order to complete a task given and it can b
6 min read
Basic Calculator Program Using Java
Create a simple calculator which can perform basic arithmetic operations like addition, subtraction, multiplication, or division depending upon the user input. Example: Enter the numbers: 2 2 Enter the operator (+,-,*,/) + The final result: 2.0 + 2.0 = 4.0ApproachTake two numbers using the Scanner class. The switch case branching is used to execute
2 min read
Features of C Programming Language
C is a procedural programming language. It was initially developed by Dennis Ritchie in the year 1972. It was mainly developed as a system programming language to write an operating system. The main features of C language include low-level access to memory, a simple set of keywords, and a clean style, these features make C language suitable for sys
3 min read
Java Assignment Operators with Examples
Operators constitute the basic building block of any programming language. Java too provides many types of operators which can be used according to the need to perform various calculations and functions, be it logical, arithmetic, relational, etc. They are classified based on the functionality they provide. Types of Operators: Arithmetic OperatorsU
7 min read
Java Arithmetic Operators with Examples
Operators constitute the basic building block to any programming language. Java too provides many types of operators which can be used according to the need to perform various calculations and functions, be it logical, arithmetic, relational, etc. They are classified based on the functionality they provide. Here are a few types: Arithmetic Operator
6 min read
For Loop in Java
Loops in Java come into use when we need to repeatedly execute a block of statements. Java for loop provides a concise way of writing the loop structure. The for statement consumes the initialization, condition, and increment/decrement in one line thereby providing a shorter, easy-to-debug structure of looping. Let us understand Java for loop with
7 min read
Java do-while loop with Examples
Loops in Java come into use when we need to repeatedly execute a block of statements. Java do-while loop is an Exit control loop. Therefore, unlike for or while loop, a do-while check for the condition after executing the statements of the loop body. Syntax: do { // Loop Body Update_expression } // Condition check while (test_expression); Note: The
5 min read
Structures in C++
We often come around situations where we need to store a group of data whether of similar data types or non-similar data types. We have seen Arrays in C++ which are used to store set of data of similar data types at contiguous memory locations.Unlike Arrays, Structures in C++ are user defined data types which are used to store group of items of non
5 min read
Building Heap from Array
Given an array of N elements. The task is to build a Binary Heap from the given array. The heap can be either Max Heap or Min Heap. Examples: Input: arr[] = {4, 10, 3, 5, 1}Output: Corresponding Max-Heap: 10 / \ 5 3 / \4 1 Input: arr[] = {1, 3, 5, 4, 6, 13, 10, 9, 8, 15, 17}Output: Corresponding Max-Heap: 17 / \ 15 13 / \ / \ 9 6 5 10 / \ / \ 4 8 3
14 min read
Data encryption standard (DES) | Set 1
This article talks about the Data Encryption Standard (DES), a historic encryption algorithm known for its 56-bit key length. We explore its operation, key transformation, and encryption process, shedding light on its role in data security and its vulnerabilities in today's context. What is DES?Data Encryption Standard (DES) is a block cipher with
15+ min read
Introduction to Internet of Things (IoT) - Set 1
IoT stands for Internet of Things. It refers to the interconnectedness of physical devices, such as appliances and vehicles, that are embedded with software, sensors, and connectivity which enables these objects to connect and exchange data. This technology allows for the collection and sharing of data from a vast network of devices, creating oppor
9 min read
Basics of Computer and its Operations
Introduction : A computer is an electronic device that can receive, store, process, and output data. It is a machine that can perform a variety of tasks and operations, ranging from simple calculations to complex simulations and artificial intelligence. Computers consist of hardware components such as the central processing unit (CPU), memory, stor
12 min read
Block Cipher modes of Operation
Encryption algorithms are divided into two categories based on the input type, as a block cipher and stream cipher. Block cipher is an encryption algorithm that takes a fixed size of input say b bits and produces a ciphertext of b bits again. If the input is larger than b bits it can be divided further. For different applications and uses, there ar
5 min read
Carrier Sense Multiple Access (CSMA)
This method was developed to decrease the chances of collisions when two or more stations start sending their signals over the data link layer. Carrier Sense multiple access requires that each station first check the state of the medium before sending. Prerequisite - Multiple Access Protocols Vulnerable Time: Vulnerable time = Propagation time (Tp)
6 min read
Carry Look-Ahead Adder
The adder produce carry propagation delay while performing other arithmetic operations like multiplication and divisions as it uses several additions or subtraction steps. This is a major problem for the adder and hence improving the speed of addition will improve the speed of all other arithmetic operations. Hence reducing the carry propagation de
5 min read
Phases of a Compiler
Prerequisite - Introduction of Compiler design We basically have two phases of compilers, namely the Analysis phase and Synthesis phase. The analysis phase creates an intermediate representation from the given source code. The synthesis phase creates an equivalent target program from the intermediate representation. A compiler is a software program
7 min read
Introduction of Compiler Design
The compiler is software that converts a program written in a high-level language (Source Language) to a low-level language (Object/Target/Machine Language/0, 1's). A translator or language processor is a program that translates an input program written in a programming language into an equivalent program in another language. The compiler is a type
9 min read
Introduction of Theory of Computation
Automata theory (also known as Theory Of Computation) is a theoretical branch of Computer Science and Mathematics, which mainly deals with the logic of computation with respect to simple machines, referred to as automata. Automata* enables scientists to understand how machines compute the functions and solve problems. The main motivation behind dev
3 min read
goto Statement in C
The C goto statement is a jump statement which is sometimes also referred to as an unconditional jump statement. The goto statement can be used to jump from anywhere to anywhere within a function. Syntax: Syntax1 | Syntax2 ---------------------------- goto label; | label: . | . . | . . | . label: | goto label; In the above syntax, the first line te
3 min read
std::gcd | C++ inbuilt function for finding GCD
In many competitive programming problems, we need to find greatest common divisor also known as gcd. Euclids algorithm to find gcd has been discussed here.C++ has the built-in function for calculating GCD. This function is present in header file. Syntax for C++14 : Library: 'algorithm' __gcd(m, n) Parameter : m, n Return Value : 0 if both m and n a
2 min read
C Library math.h Functions
The math.h header defines various C mathematical functions and one macro. All the functions available in this library take double as an argument and return double as the result. Let us discuss some important C math functions one by one. C Math Functions1. double ceil (double x) The C library function double ceil (double x) returns the smallest inte
6 min read
Difference Between Structure and Union in C
Structures in C is a user-defined data type available in C that allows to combining of data items of different kinds. Structures are used to represent a record. Defining a structure: To define a structure, you must use the struct statement. The struct statement defines a new data type, with more than or equal to one member. The format of the struct
4 min read
SQL Functions (Aggregate and Scalar Functions)
SQL Functions are built-in programs that are used to perform different operations on the database. There are two types of functions in SQL: Aggregate FunctionsScalar FunctionsSQL Aggregate FunctionsSQL Aggregate Functions operate on a data group and return a singular output. They are mostly used with the GROUP BY clause to summarize data.  Some com
4 min read
Command Line Arguments in Java
Java command-line argument is an argument i.e. passed at the time of running the Java program. In Java, the command line arguments passed from the console can be received in the Java program and they can be used as input. The users can pass the arguments during the execution bypassing the command-line arguments inside the main() method. Working com
3 min read
Data Abstraction and Data Independence
Database systems comprise complex data structures. In order to make the system efficient in terms of retrieval of data, and reduce complexity in terms of usability of users, developers use abstraction i.e. hide irrelevant details from the users. This approach simplifies database design.  Level of Abstraction in a DBMSThere are mainly 3 levels of da
4 min read
Article Tags :
Practice Tags :