banner



How To Install G++ In Ubuntu

While working every bit an application developer, it is mutual practice that some projects require different compiler versions for treatment source code. With the rapid increment of software applied science, you oft find yourself where you need to apply a specific compiler for a projection. Today, different compiler versions are using for compiling the C programs. Hither, we will talk nigh the G++ GNU compiler; a Linux arrangement compiler specifically used to compile C++ programs. The file extensions of these programs are .c and .cpp that are compiled using the M++ compiler.

This article aims to provide a detailed guide on installing and using the Grand++ compiler on the Ubuntu twenty.04 LTS system. You can attain this goal by installing some development tools named build-essential packages on your organization.

Installation of g++ on Ubuntu 20.04 system

Perform the below-mentioned steps to install k++ on the Ubuntu system:

Stride ane: Install build-Essentials

The Ubuntu official default repository contains a number of development tools or packages. These tools you lot can install directly by installing a Ubuntu meta-package named "build-essential" on your system that includes the of import evolution libraries, GNU debugger, and compiler collections required for compiling C/C++ applications. Therefore, it is required to install build-essentials on your system before installing any compiler. Type the following terminal control to install development tools:

$ sudo apt update

$ sudo apt install build-essential


The above meta-package installs the number of packages including g++ automatically, gcc, and make.

Pace two: Check m++ compiler version

In one case all evolution packages are installed, type the post-obit command to check the installed version of the g++ compiler:

The latest installed k++ version displays on the terminal as follows:

Install multiple g++ compiler versions on Ubuntu 20.04

First, install build-essentials development tools and then use the following command to install multiple chiliad++ compilers:

$ sudo apt install build-essential

$ sudo apt -y install chiliad++-seven g++-8 g++-9 g++-10


The higher up command will consummate in a few minutes after installing all g++ compiler versions on your Ubuntu arrangement.

Create a list of 1000++ alternatives using update-alternatives tools

The update-alternative tool is used to create the list of thou++ multiple compiler alternatives. Using the beneath-mentioned commands, user can create the multiple chiliad++ alternatives list on Ubuntu system:

$ sudo update-alternatives --install /usr/bin/ m++ yard++ /usr/bin/chiliad++-vii 7

$ sudo update-alternatives --install /usr/bin/ yard++ g++ /usr/bin/g++-8 8

$ sudo update-alternatives --install /usr/bin/ g++ g++ /usr/bin/g++-ix 9

$ sudo update-alternatives --install /usr/bin/ thousand++ thousand++ /usr/bin/g++-10 ten


Now, display the list of g++ alternatives on your Ubuntu system by using the following update-alternatives command:

$ sudo update-alternatives --config g++

Check the available k++ version in the list that would display on the terminal as follows:

Cull the thou++ compiler version that you want to use as the default compiler for software development. Printing 'enter' to keep the current pick set as default or select the number from the g++ alternatives list.

For instance, to use the g++-9 version fix as default, enter the number 'iv'. Hence, this version volition exist ready equally default. Similarly, if you want to switch to some other g++ version then, repeat the configuration procedure and select the desired g++ version from the alternatives.

Installing k++ and gcc compiler in a single command

Nigh Linux users desire to install multiple gcc and g++ compiler alternatives on the same arrangement. In this case, you can also install gcc and 1000++ compilers using simply a single command on your Ubuntu system.

$ sudo apt -y install gcc-7 chiliad++-vii gcc-viii 1000++-8 gcc-9 thousand++-nine


Follow the same procedure for configuring gcc compiler alternatives. Utilise the update-alternatives control to create the list of gcc compilers.

Subsequently that, select the default gcc version or alternative using the 'config gcc' command, which is also mentioned in a higher place.

$ sudo update-alternatives --config gcc

How to employ of g++ on Ubuntu 20.04?

Compiling a C++ program using the chiliad++ is quite piece of cake and simple. We volition create and execute the source code of the c++ plan.

For example, to display a message 'Hello, Welcome to the LinuxHint tutorials!' create the following source code in a text file:

#include <iostream>

using namespace std;

int chief( )

{

    cout << "Howdy, Welcome to the LinuxHint Tutorials!\n";

render 0;

}


Now, relieve the above source code and rename the file with 'welcome.cc'. You tin can assign whatsoever name to this file with the '.cc' extension.

Compile the higher up source lawmaking using the g++ compiler by running the following command:

$ g++ -o welcome welcome.cc

The above command creates a binary file named 'welcome' in the current directory where you lot run the command. Execute the 'welcome' executable plan past using the following control:

The post-obit message should display on the concluding after running the above control:

Decision

We learned about the installation of 1000++ on the Ubuntu 20.04 organization in this article. Nosotros demonstrated how to install dissimilar g++ compiler versions at the same fourth dimension on a Ubuntu system. Moreover, we accept besides explained how to compile a program using the one thousand++ compiler. I hope all the above information about yard++ is enough for your understanding. Visit GNU C compilers to go more details most Gcc or C compilers. Send usa your feedback well-nigh this tutorial through comments.

About the author

Samreena Aslam holds a master'south degree in Software Technology. Currently, she's working as a Freelancer & Technical writer. She's a Linux enthusiast and has written various articles on Calculator programming, different Linux flavors including Ubuntu, Debian, CentOS, and Mint.

Source: https://linuxhint.com/install-and-use-g-on-ubuntu/

Posted by: mcgaughtheyeary.blogspot.com

0 Response to "How To Install G++ In Ubuntu"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel