How to Install the GCC C++ Compiler on Linux Mint

If you try to compile C++ code on a Linux Mint or Ubuntu computer using gcc, the compile will fail. C++ code needs to be compiled using the g++ compiler which must first be installed. This article explains how to install the GCC C++ compiler on Linux Mint and Ubuntu based systems.

Trying to compile a C++ program with gcc gives the following error.

If g++ is used to compile the C++ program, an error message appears that indicates that g++ is currently not installed:

Installing the GCC C++ Compiler

Before installing new software it is best to update the system. Open a terminal window and enter the following.

Now install the C++ compiler by entering the following:

Compiling a Simple C++ Program

The simple “Hello World” C++ code shown below can be used to test if the C++ compiler is installed and working. Save the code to a text file called hello.cpp.

Compile the above program using the GCC C++ compiler as shown below. Open a terminal window and change directory to the directory containing the hello.cpp file before compiling.

This will create an executable file called hello which can be run from the terminal window by entering the following command.

The hello.cpp program is shown in the Geany editor here.

Hello World C++ Program Code
Hello World C++ Program Code

This is what the command line looks like after compiling the hello.cpp program using the g++ compiler and then running the hello application.

C++ Compiling in the Terminal Window
C++ Compiling in the Terminal Window

Hello, world! is printed in the terminal window when the program is run.

Leave a Reply

Your email address will not be published. Required fields are marked *