How to install GCC on Linux Mint 18.3

To install GCC on Linux Mint 18.3

The GNU Compiler Collection (GCC) is a compiler system produced by the GNU project to support various programming languages. GCC is a key component of the GNU toolchain and the standard compiler for most UNIX like OS. It is mainly designed for C and C++ compiler.  In this tutorial, we will see how to install and remove GCC  on Linux Mint 18.3. 

 

Installing GCC

First, make sure you  add the necessary repo by making use of the following command. 

linuxhelp ~ # add-apt-repository ppa:eugenesan/ppa
You are about to add the following PPA:
This repository contains collection of customized, updated, ported and backported
packages for two last LTS releases and latest pre-LTS release.
Packages for older releases relocated to ppa:eugenesan/archive or deleted.

+-------------------------------------------------------------------------------------+
| Disclaimer:
+-------------------------------------------------------------------------------------+ 

.
.
8313A596
gpg: requesting key 8313A596 from hkp server keyserver.ubuntu.com
gpg: key 8313A596: public key " Launchpad synergy+"  imported
gpg: Total number processed: 1
gpg:               imported: 1  (RSA: 1)


After adding repo, you need to update the system repo package using the following command

linuxhelp ~ # apt-get update 
Hit:1 http://archive.ubuntu.com/ubuntu xenial InRelease
Ign:2 http://packages.linuxmint.com sylvia InRelease                                                                                      
Get:3 http://ppa.launchpad.net/eugenesan/ppa/ubuntu xenial InRelease [17.5 kB]                                  
Hit:4 http://archive.canonical.com/ubuntu xenial InRelease                                
Get:5 http://archive.ubuntu.com/ubuntu xenial-updates InRelease [102 kB]                                                                       
Get:6 http://packages.linuxmint.com sylvia Release [24.2 kB]                                                        
.
.
Get:28 http://archive.ubuntu.com/ubuntu xenial-backports/universe Translation-en [3,812 B]                                                     
Get:29 http://security.ubuntu.com/ubuntu xenial-security/universe i386 Packages [281 kB]                                                       
Get:30 http://security.ubuntu.com/ubuntu xenial-security/universe Translation-en [121 kB]                                                      
Fetched 5,472 kB in 11s (477 kB/s)                                                                                                             
Reading package lists... Done


And then, after updating install the GCC  using the following command. 

linuxhelp ~ # apt-get install gcc-4.9 
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following additional packages will be installed:
  cpp-4.9 gcc-4.9-base libasan1 libgcc-4.9-dev
Suggested packages:
  gcc-4.9-locales gcc-4.9-multilib gcc-4.9-doc libgcc1-dbg libgomp1-dbg libitm1-dbg libatomic1-dbg libasan1-dbg liblsan0-dbg libtsan0-dbg
  libubsan0-dbg libcilkrts5-dbg libquadmath0-dbg
.
.
Setting up cpp-4.9 (4.9.3-13ubuntu2) ...
Setting up libasan1:amd64 (4.9.3-13ubuntu2) ...
Setting up libgcc-4.9-dev:amd64 (4.9.3-13ubuntu2) ...
Setting up gcc-4.9 (4.9.3-13ubuntu2) ...
Processing triggers for libc-bin (2.23-0ubuntu9) ...


Verify the installation using the following command . 

linuxhelp ~ # gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/5/lto-wrapper
Target: x86_64-linux-gnu

 

Now, let’ s see how to remove the GCC, use the following command to remove GCC  from the system.

linuxhelp ~ # apt-get remove gcc-4.9
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages were automatically installed and are no longer required:
  cpp-4.9 gcc-4.9-base libasan1 libgcc-4.9-dev
Use ' sudo apt autoremove'  to remove them.
The following packages will be REMOVED:
  gcc-4.9
0 upgraded, 0 newly installed, 1 to remove and 287 not upgraded.
After this operation, 17.5 MB disk space will be freed.
Do you want to continue? [Y/n] y
(Reading database ... 224081 files and directories currently installed.)
Removing gcc-4.9 (4.9.3-13ubuntu2) ...
Processing triggers for man-db (2.7.5-1) ...

That’ s it this is how we install and remove gcc on linuxmint 18.3

Tag : Linux Mint GCC
FAQ
Q
GCC miscompiles my code when optimizing, how to find whether it is a bug in my code or in GCC ?
A
Useful warnings "-Wall -Wextra -Wstrict-aliasing=3 -Waggressive-loop-optimizations"

Try adding -fno-strict-aliasing. If it works, your code most probably breaks the strict aliasing rules that the compiler is using for optimization.

Try adding -fwrapv. If it works, your code most probably has undefined behaviour because of integer overflow.

Try adding -fno-aggressive-loop-optimizations. If it works, your code most probably has undefined behaviour because of some loop.

Try adding -fno-delete-null-pointer-checks. GCC removes NULL pointer checks when it can prove that the pointer cannot be NULL (e.g., 'this' in C++ can never be NULL). If the execution path leading to the pointer being NULL triggers undefined behaviour, then the path cannot (should not) happen and the pointer can never be NULL.

Try adding -fno-lifetime-dse. If it works, your code has undefined behaviour according to the C++ standard, probably when using placement new. See also PR71885.

Compile without optimizations and with the -fsanitize= option.

For a locking or race condition issue, you might consider using hellgrind to gain an understanding of what's going wrong without having to further reduce the source. Once you have that understanding, it may be possible to show the problem with simpler source or just explain what's going wrong (if indeed it is a compiler issue).

GCC attempts to diagnose some undefined behaviours, but this is not possible in all cases. If GCC missed a warning and you know how to implement it, please send even a rough working patch. Otherwise, just assume there is no easy/efficient way to diagnose that particular case.
Q
What is the status of adding the UTF-8 support for identifier names in GCC?
A
Since GCC 5, the option -fextended-identifiers is enabled by default for C++, and for C99 and later C versions. This only supports UCNs in identifiers, not extended characters represented other than with UCNs. Support for actual UTF-8 in identifiers is still pending (please contribute!)

So how do you express UCN in the code? By using the \uNNNN or \UNNNNNNNN syntax. For example, pipe your code through

perl -pe 'BEGIN { binmode STDIN, ":utf8"; } s/(.)/ord($1) < 128 ? $1 : sprintf("\\U%08x", ord($1))/ge;'

or something similar to convert extended characters to UCNs.

A longer example:

//file UCN_almost_UTF8_identifiers.cpp

#include
int main()
{
double Δ_电场velocity(0);
std::cout << "Δ_v电场elocity= " << Δ_电场velocity << "\n";
}

// with following makefile:

UCN_almost_UTF8_identifiers: UCN_almost_UTF8_identifiers.cpp
to_UCN.sh UCN_almost_UTF8_identifiers.cpp
g++ -fextended-identifiers -o UCN_almost_UTF8_identifiers /tmp/UCN_almost_UTF8_identifiers.cpp

//and the helper script: to_UCN.sh:

#!/bin/bash
cat $1 | perl -pe 'BEGIN { binmode STDIN, ":utf8"; } s/(.)/ord($1) < 128 ? $1 : sprintf("\\U%08x", ord($1))/ge;' > /tmp/$1
Q
How to install GCC on Ubuntu?
A
For the installation of the GCC on Ubuntu, use the following link as given below "https://www.linuxhelp.com/how-to-install-gcc-on-ubuntu-17-04/"
Q
How to get the official documentation for the GCC?
A
Get the official documentation for the GCC, use the following link as given below "https://gcc.gnu.org/install/".
Q
Whether does the GCC work on any platform?
A
The host/target specific installation notes for GCC include information about known problems

with installing or using GCC on particular platforms. These are included in the sources for a rel