How To Install GCC Compiler On CentOS 7 - Linuxize
Có thể bạn quan tâm
The GNU Compiler Collection (GCC) is a collection of compilers and libraries for C, C++, Objective-C, Fortran, Ada, Go , and D, programming languages. Many open-source projects including the GNU tools and the Linux kernel are compiled with GCC.
This tutorial explains how to install the GCC compiler on CentOS 7. We’ll explain how to install the distro stable version and the newer version of GCC available from the SCL repository.
Prerequisites #
To add new repositories and install packages on your CentOS system, you must be logged in as root or user with sudo privileges .
Installing GCC on CentOS #
The default CentOS repositories contain a package group named Development Tools that contains the GCC compiler and a lot of libraries and other utilities required for compiling software.
To install the Development Tools including the GCC Compiler, run:
sudo yum group install "Development Tools"The command installs a bunch of new packages including gcc, g++ and make.
You may also want to install the manual pages about using GNU/Linux for development:
sudo yum install man-pagesValidate that the GCC compiler is successfully installed by using the gcc --version command which prints the GCC version:
gcc --versionThe default version of GCC available in the CentOS 7 repositories is 4.8.5:
gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-36) Copyright (C) 2015 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.That’s it. GCC is now installed on your system, and you can start using it.
Compiling a Hello World Example #
Compiling a basic C or C++ program using GCC is an easy task. Open your text editor and create the following file:
nano hello.chello.c#include <stdio.h>int main() { printf ("Hello World!\n"); return 0; }Save the file and compile it into an executable by running the following command:
gcc hello.c -o helloThis will create a binary file named hello in the same directory where you run the command.
Execute the hello program with:
./helloThe program should display:
Hello World!Installing Multiple GCC Versions #
In this section, we will provide instructions about how to install and use multiple versions of GCC on CentOS 7. The newer versions of the GCC compiler include support for new languages, better performance, extended features.
Software Collections , also known as SCL is a community project that allows you to build, install, and use multiple versions of software on the same system, without affecting system default packages. By enabling Software Collections, you gain access to the newer versions of programming languages and services which are not available in the core repositories.
The SCL repositories provide a package named Developer Toolset, which includes newer versions of the GNU Compiler Collection, and other development and debugging tools.
First, install the CentOS SCL release file. It is part of the CentOS extras repository and can be installed by running the following command:
sudo yum install centos-release-sclCurrently, the following Developer Toolset collections are available:
- Developer Toolset 7
- Developer Toolset 6
In this example, we’ll install the Developer Toolset version 7. To do so type the following command on your CentOS 7 terminal:
sudo yum install devtoolset-7To access GCC version 7, you need to launch a new shell instance using the Software Collection scl tool:
scl enable devtoolset-7 bashNow if you check the GCC version, you’ll notice that GCC 7 is the default version in your current shell:
gcc --versiongcc (GCC) 7.3.1 20180303 (Red Hat 7.3.1-5) Copyright (C) 2017 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.At this point, you can use the newer GCC version just like any other regular tool.
Conclusion #
You have successfully installed GCC on your CentOS 7. You can now visit the official GCC Documentation page and learn how to use GCC and G++ to compile your C and C++ programs.
If you hit a problem or have feedback, leave a comment below.
gcc centosTừ khóa » Cài đặt Gcc Trên Centos 7
-
Cách Cài đặt Trình Biên Dịch Gcc Trên Centos 7 - Joe Comp
-
Cách Cài đặt Trình Biên Dịch GCC Trên CentOS 7
-
Hướng Dẫn Cài đặt Gcc-7.3.0 Trên CentOS 6 Và CentOS 7
-
Cài đặt Gcc Mới Nhất Từ Source Trên Centos 7 - DevOps VN
-
Cài đặt GCC Trên CentOS 8 - CLOUD VIỆT - CloudViet
-
Cách Cài đặt GCC Trên CentOS 6
-
Cách Cài đặt Gcc 4.7.x / 4.8.x Trên CentOS - Bổ-tú
-
[Centos] Hưỡng Dẫn Upgrade Gcc, G++ Lên Version 4.8 Trên Centos 6
-
Xử Lý Lỗi CXXABI 1.3.9 Not Found Trên CentOS 7 Chạy DirectAdmin
-
Hướng Dẫn Cài đặt DirectAdmin Trên CentOS 7 & 8 - Blog KDATA
-
Hướng Dẫn Upgrade Kernel Trên Centos 7 - VinaHost
-
Hướng Dẫn Cài đặt Webvirtmgr Trên CentOS 7 - Blog - Cloud365
-
Hệ điều Hành - OSM201 | Hướng Dẫn Cài đặt GCC Trên Terminal
-
Cách Cài đặt Perlbrew Và Quản Lý Nhiều Phiên Bản Perl 5 Trên ...