In this tutorial, we will demonstrate the installation and usage of g++ in Debian.
How to Install g++ in Debian
The meta package known as build-essential which contains the g++ compiler, libraries, and other utilities for compiling software is present in the default repository of Debian. Update the system before starting the installation procedure through the following command:
Run the following command to install the built-essential on Debian:
sudo apt install build-essential
Verify the successful installation of g++ through the following command:
How to Use g++ in Debian
Using g++ for the compilation of .cpp files is simple. Create a newfile.cpp with the following command:
Add the text in the file, for example, I have added the following code in the text file:
std::cout<<“Hello this is Linuxhint”;
Save the file by pressing Ctrl + X and run the following command to make it an executable file:
g++ <program-name>.cpp -o <executable-filename>
Note: g++ can also compile C language code.
For example, I am compiling the newfile.cpp into an executable file named newfile:
g++ newfile.cpp -o newfile
The compiler will create the binary file named newfile in the same directory, and run the file via the below-given command:
In my case, the executable file is newfile so the output is Hello this is Linuxhint.
The g++ converts the .cpp high-level language file into a low-level language file by making it executable. Installation is simple as it is present in the default repository of Debian. In the above guide, we have successfully installed and used g++ on Debian.