Install GCC C/C++ Compilers

This section provides a tutorial example on how to install GCC C/C++ compiler on CentOS systems.

If you want develop your own C/C++, or compile third party C/C++ source code, you need install GCC C/C++ compilers as shown in this tutorial.

1. Install GCC C compiler:

herong$ dnf info gcc
Available Packages
Name         : gcc
Version      : 8.3.1
Release      : 4.5.el8
Architecture : x86_64
Size         : 23 M
Source       : gcc-8.3.1-4.5.el8.src.rpm
Repository   : AppStream
Summary      : Various compilers (C, C++, Objective-C, ...)
URL          : http://gcc.gnu.org
License      : GPLv3+ and GPLv3+ with exceptions and GPLv2+ with ...
Description  : The gcc package contains the GNU Compiler Collection
             : version 8. You'll need this package in order to compile
             : C code.

herong$ sudo dnf install gcc
...
Installed:
  gcc-8.3.1-4.5.el8.x86_64
  annobin-8.78-1.el8.x86_64
  cpp-8.3.1-4.5.el8.x86_64
  isl-0.16.1-6.el8.x86_64
  glibc-devel-2.28-72.el8.x86_64
  glibc-headers-2.28-72.el8.x86_64
  kernel-headers-4.18.0-147.5.1.el8_1.x86_64
  libxcrypt-devel-4.1.1-4.el8.x86_64

2. Verify GCC installation:

(cpp - The C preprocessor)
herong$ cpp --version
cpp (GCC) 8.3.1 20190507 (Red Hat 8.3.1-4)
Copyright (C) 2018 Free Software Foundation, Inc.

(gcc - The GNU project C compiler)
herong$ gcc --version
gcc (GCC) 8.3.1 20190507 (Red Hat 8.3.1-4)
Copyright (C) 2018 Free Software Foundation, Inc.

(cc - Alias of gcc)
herong$ ls -l /usr/bin/cc
lrwxrwxrwx. 1 root root 3 Nov  5 23:36 /usr/bin/cc -> gcc

3. Compile and run a C program, hello.c:

herong$ vi hello.c
#include<stdio.h>
int main(void) {
 printf("Hello world! - From C.\n");
 return 0;
}

herong$ gcc hello.c

herong$ ./a.out
Hello world! - From C.

4. Install GCC C++ compiler:

herong$ dnf info gcc-c++
Available Packages
Name         : gcc-c++
Version      : 8.3.1
Release      : 4.5.el8
Architecture : x86_64
Size         : 12 M
Source       : gcc-8.3.1-4.5.el8.src.rpm
Repository   : AppStream
Summary      : C++ support for GCC
URL          : http://gcc.gnu.org
License      : GPLv3+ and GPLv3+ with exceptions and GPLv2+ with ...
Description  : This package adds C++ support to the GNU Compiler
             : Collection. It includes support for most of the current 
             : C++ specification, including templates and exception 
             : handling.

herong$ sudo dnf install gcc-c++
...
Installed:
  gcc-c++-8.3.1-4.5.el8.x86_64
  libstdc++-devel-8.3.1-4.5.el8.x86_64

Complete!

5. Verify GCC installation:

(g++ - The GNU project C++ compiler)
herong$ gcc --version
g++ (GCC) 8.3.1 20190507 (Red Hat 8.3.1-4)
Copyright (C) 2018 Free Software Foundation, Inc.

6. Compile and run a C++ program, hello.c:

herong$ vi hello.cpp
#include "iostream"
int main(void) {
    std::cout <<  "Hello world! From C++.\n";
    return 0;
}

herong$ g++ hello.cpp

herong$ ./a.out
Hello world! From C++.

Table of Contents

 About This Book

 Introduction to Linux Systems

 Process Management

 Files and Directories

 Running Apache HTTP Server (httpd) on Linux Systems

 Running Apache Tomcat on Linux Systems

 Running PHP Scripts on Linux Systems

 Running MySQL Database Server on Linux Systems

 Running Python Scripts on Linux Systems

 Conda - Environment and Package Manager

GCC - C/C++ Compiler

Install GCC C/C++ Compilers

 "g++ --verbose" - GCC Compiler Steps and Settings

 "g++ -I..." and CPATH Environment Variable

 "g++ -l..." to Link with Library Files

 "g++ -c" and "ar src" to Build Static Library

 "g++ -shared" to Build Dynamic Library

 "ldd" - Dynamic Library Dependency Checker

 "make" - Manage Program Build Process

 OpenJDK - Open-Source JDK

 Graphics Environments on Linux

 SquirrelMail - Webmail in PHP

 Tools and Utilities

 References

 Full Version in PDF/EPUB