Arch linux make gcc

How to Install GCC for Arch Linux

GCC (GNU Compiler Collection) comprises compilers for well-known programming languages such as C, C++, Go, Fortran, Objective-C, and many more. The GCC is completely free and provides cross-platform support for Linux, Windows, and multiple BSD-based systems.

Apart from this, one can suggest or make enhancements to GCC and you can utilize the enhancements done by other developers/users as well. Moreover, the GCC can be used to make executable files for other systems which makes it the best choice for embedded systems (as they don’t have any compiler).

Keeping in view the importance of GCC, this guide demonstrates the step-by-step procedure to install GCC on Arch Linux.

How to install GCC on Arch Linux

The GCC is available on the official repository of Arch, thus the Arch package manager can be used to install it.

Step 1: First, synchronize and update the package’s database using the following command.

Step 2 (optional): After synchronizing the database, you can look for the availability of GCC on Arch Linux by using the following command.

The output shows the dependencies that are available on the official repository of Arch Linux.

Step 3: Install GCC on Arch Linux by issuing the following command in the terminal.

Once installed successfully, verify its version by issuing the following command.

How to install older versions of GCC on Arch Linux

What if you have created a project using an old version of GCC and you are unable to compile it? For this, you may need older versions.

The older versions can be obtained easily from AUR (Arch User Repository) and to access it, you may need an AUR helper (yay, pacaur)To do so, you can make use of any AUR helper (pacaur, yay,).

For instance, the command written below will install “gcc 4.9” on your Arch Linux system.

How to remove GCC on Arch Linux

The GCC can be removed from your Arch Linux system by providing the following command.

However, you can use the -Rcnu flag to remove GCC and the unnecessary dependencies as well. In our case, the following command would remove GCC and all its dependencies.

Читайте также:  Apt transport https kali linux

The output shows that the gcc and all its dependencies have been removed successfully.

Conclusion

GCC (GNU Compiler Collection) is a resourceful compiler that can be obtained on Arch Linux with the help of a package manager of Arch Linux. GCC provides front ends for various programming languages such as C, C++, Go, Fortran, and many more. This guide demonstrates the way to install the latest release as well as any older version of GCC on Arch Linux.

Источник

Compile C Program in Linux Using GCC

The full form of GCC is GNU Compiler Collection. GCC has compilers for C, C++, Objective-C, Ada, Go, Fortran and many more programming languages. These are all open source and free to use.

In this article, I will show you how to install GCC and compile C programs in Linux using GCC. I will use Debian 9 Stretch for the demonstration. But I will show you how to install GCC on wide variety of Linux distributions. Let’s get started.

Installing GCC on Ubuntu and Debian GNU/Linux:

On Ubuntu and Debian GNU/Linux distributions, GCC is really easy to install as all the required packages are available in the official package repository of Ubuntu and Debian. There is a meta package called build-essential, which installs everything you need in order to compile C and C++ programs on Ubuntu and Debian GNU/Linux distribution.

First, update the APT package repository cache with the following command:

The APT package repository cache should be updated.

Now install build-essential with the following command:

Now press y and then press to continue.

Now you can check whether GCC is working with the following command:

Installing GCC on Linux Mint:

You can install GCC on Linux Mint the same way as in Ubuntu/Debian as shown in the earlier section of this article.

Installing GCC on CentOS 7 and Fedora:

On CentOS 7 and Fedora, GCC is easier to install as well. The required packages are available in the official package repository of CentOS 7 and Fedora. You can install the Development Tools group to install all the required packages to compile C and C++ programs on CentOS 7 and Fedora.

First, update the YUM database with the following command:

YUM database should be updated.

Now install Development Tools group packages with the following command:

Now press y and then press to continue.

If you see this message, just press y and then press .

Now you can check whether GCC is working with the following command:

Installing GCC on Arch Linux:

You can install GCC on Arch Linux too. All the required packages are available in the Arch package repository. Arch also has a meta package base-devel, which you can install to get all the required tools needed to compile C and C++ programs on Arch Linux.

First, update the Pacman database with the following command:

Читайте также:  Linux so base address

Pacman database should be updated. In my case, it was already up to date.

Now install base-devel package with the following command:

Now press to select all unless you want to install very specific set of packages.

You may see something like this. It’s nothing serious as far as I know. It’s just a package was renamed from pkg-config to pkgconf. So Pacman is asking you whether you want to use the new package and remove the old one. Just press y and then press .

Now press y and then press .

Now check whether GCC is working with the following command:

Writing Your First C Program:

Now let’s write a very simple C program, which we will compile in the next section of this article below using GCC C compiler.

First, create a project directory (I am going to call it hello) with the following command:

Now navigate to the newly created directory with the following command:

Now create a new C source file (I am going to call it main.c) here with the following command:

Now open the file with any text editor (such as vim, nano, gedit, kate etc) of your choice.

To open the file with nano, run the following command:

To open the file with vim, run the following command:

To open the file with Gedit, run the following command:

To open the file with Kate, run the following command:

I am going to use Gedit text editor in this article.

Now type in the following lines and save the file.

Here, line 1 includes the stdio.h header file. It has function definition for the printf() function I used on line 4.

Every C program must have a main() function. It is the function that will get called when you run a C program. If you don’t write a main() function, you can’t run the C program. So I wrote a main() function in line 3line 7.

Inside the main() function, I called printf() library function in line 4 to print some text to the screen.

Finally, in line 6, I returned 0 from the program. On Linux world, when a program returns 0, it means the program ran successfully. You can return any integer you like but there are some Linux specific rules on what return value means what.

In the next section, I will show you how to compile the C program with GCC and run it.

Compiling and Running C Programs with GCC:

The command to compile a C source file with GCC is:

NOTE: Here, SOURCE_FILES is a whitespace separated list of C source files. The compiled executable file will be saved as OUTPUT_BINARY in your current working directory.

In our case, the main.c source file doesn’t depend on other C source file, so we can compile it with the following command:

The source file main.c should be compiled and hello executable file should be created as you can see in the screenshot below.

Читайте также:  What is linux image server

Now, you can run the hello executable binary file as follows:

As you can see, the correct output is printed on the screen.

So that’s basically how you use GCC to compile C programs on Linux. Thanks for reading this article.

About the author

Shahriar Shovon

Freelancer & Linux System Administrator. Also loves Web API development with Node.js and JavaScript. I was born in Bangladesh. I am currently studying Electronics and Communication Engineering at Khulna University of Engineering & Technology (KUET), one of the demanding public engineering universities of Bangladesh.

Источник

Как установить GCC для Arch Linux?

Как обновить Arch Linux

Советы и хитрости

GCC (GNU Compiler Collection) включает компиляторы для известных языков программирования, таких как C, C++, Go, Fortran, Objective-C и многих других. GCC полностью бесплатен и обеспечивает кроссплатформенную поддержку для Linux, Windows и нескольких систем на базе BSD.

Кроме того, можно предлагать или вносить улучшения в GCC, а также использовать улучшения, сделанные другими разработчиками/пользователями. Кроме того, GCC можно использовать для создания исполняемых файлов для других систем, что делает его лучшим выбором для встраиваемых систем (поскольку у них нет компилятора).

Учитывая важность GCC, в этом руководстве демонстрируется пошаговая процедура установки GCC в Arch Linux.

Как установить GCC на Arch Linux

GCC доступен в официальном репозитории Arch, поэтому для его установки можно использовать диспетчер пакетов Arch.

Шаг 1: Сначала синхронизируйте и обновите базу данных пакета с помощью следующей команды.

ачала синхронизируйте и обновите базу данных

Шаг 2 (необязательно): после синхронизации базы данных вы можете проверить доступность GCC в Arch Linux с помощью следующей команды.

Вывод показывает зависимости, доступные в официальном репозитории Arch Linux.

Шаг 3: Установите GCC в Arch Linux, введя следующую команду в терминале.

После успешной установки проверьте его версию, выполнив следующую команду.

Как установить старые версии GCC на Arch Linux

Что делать, если вы создали проект с использованием старой версии GCC и не можете его скомпилировать? Для этого вам могут понадобиться более старые версии.

Более старые версии можно легко получить из AUR (архивный пользовательский репозиторий), и для доступа к нему вам может понадобиться помощник AUR (ура, пакаур). Для этого вы можете использовать любой помощник AUR (пакаур, ура).

Например, команда, написанная ниже, установит » gcc 4.9 ″ в вашей системе Arch Linux.

Как удалить GCC в Arch Linux

GCC можно удалить из вашей системы Arch Linux, введя следующую команду.

Однако вы можете использовать флаг -Rcnu для удаления GCC и ненужных зависимостей. В нашем случае следующая команда удалит GCC и все его зависимости.

Вывод показывает, что gcc и все его зависимости были успешно удалены.

Заключение

GCC (GNU Compiler Collection) — это находчивый компилятор, который можно получить в Arch Linux с помощью менеджера пакетов Arch Linux. GCC предоставляет интерфейсы для различных языков программирования, таких как C, C++, Go, Fortran и многих других. В этом руководстве демонстрируется способ установки последней версии, а также любой старой версии GCC в Arch Linux.

Источник

Оцените статью
Adblock
detector