Installing g++ on Linux Mint 21
To install g++ on Linux Mint, follow the steps listed below:
Step 1: Update the package list of the default package manager as it is recommended before installing any application on Linux:
Step 2: Next, install g++ with the help of below command:
Step 3: Now to see if this editor is installed correctly check its version:
Compiling a C++ code using g++ on Linux Mint 21
There are few easy steps that one needs to follow to learn how to write and compile C++ code using g++ in Linux Mint 21:
Step 1: Create .cpp file with your desired name:
Step 2: Next write the C++ code in the created file, below is the simple code that I have written in the .cpp file:
#include<iostream>
using namespace std;
// Here execution of code begins
int main()
{
// displays string on screen
cout<<"Hello LinuxHint!\n";
return 0;
}
Note: Ensure that you are in the same directory where the created file is present.
Step 3: Now just the save and close the file by pressing ctrl+x and compile the file using:
Step 4: Next, run the compiled C++ file using:
So, this is how one can write and compile C++ code using the g++ compiler in Linux Mint 21.
To remove the g++ compiler from Linux Mint 21 use:
Conclusion
The primary purpose of a compiler is to convert the programming language into machine language so that machines can understand the instructions given to them. There are a variety of compilers available that support different programming languages, the g++ is mainly used to compile C and C++ language. To install g++ on Linux Mint 21 one can use its default package manager; the detailed installation process is mentioned in this guide.