0

Issue

This question, and answers containing various approaches to solving it comes up many times almost daily on our exchange here. If a search result brought you here Welcome! If a comment I left in your question linked here, you can safely assume your question could be added to the list below, as it fits in the same category:

Those are just four of the many questions tagged under [gcc] with the search term downgrade. Those readers/users knowledgeable enough to come to the exchange first almost always ask How Can I..." Those unlucky readers that tried something that failed almost always have the phrase "It Broke", or "I think I broke something". In this question and answer, I'll attempt to explain Why mixing compilers breaks all Linux's, and in the answer I'll provide the simplest way that I know to fix the issue, that doesn't cause breakage but costs a bit of overhead in terms of time and space to setup. Since this is going to be a community contributed Question and Answer, I'm kindly going to ask you to upvote this if you like my approach.

Issue Explained

TLDR: Skip Down to Why Does Downgrading Compilers Cause Issues?

I've used the picture below two or 3 times here across various answers, and feel it provides us all with a good place to start. I realize it's big, and as such, I urge reader's to open it in a separate tab and zoom etc. if you like.

Timeline of Linux Distributions

Find your distribution in that list, and then continue reading. You'll notice that your distribution has a parent distribution. OK, OK, I know the readers using the parent distributions (the ones on the far left of the timeline) are asking:

I'm using one of the ones on the far left, so where are it's parents?

And now we get to the meat of this question. For Example sake, let's fill in $X and $Y from my title (Patience Readers, $Z is coming up)

  • $X = Fedora 39
  • $Y = 13.2.1-6.fc39

Definitions

  • Distribution (Quoting Wikipedia):

A Linux distribution (often abbreviated as distro) is an operating system made from a software collection that includes the Linux kernel and often a package management system.

  • Package Management System (Quoting Again):

A package manager or package-management system is a collection of software tools that automates the process of installing, upgrading, configuring, and removing computer programs for a computer in a consistent manner

Knowing these two items helps us answer the Parent Distribution question, but unfortunately with another question: How Do the distribution maintainers create a distribution?

The Answer: All linux software minus the kernel is stored at and can be obtained from the GNU Software FTP Site in source code archives. All Linux Kernels are available for download in source code archives at The Linux Kernel Archives. In short, all Distributions begin from the same source code, including the parent distributions

Why Does Downgrading Compilers Cause Issues?

From the definition earlier, a distribution is a group or set of related software. This relation can be seen in your distribution's repository (or whatever else your distribution has chosen to name it).

At the time a new version (in our Example $X = Fedora 39) is made available the repository for that version is locked, specifically version locked, meaning that every package in that repository is now frozen in time. Once frozen it isn't altered. It can only live as long as the version is supported or die when the version is upgraded.

The tools required to build GCC are also in the now frozen repository. If a user attempts to upgrade or downgrade the GCC that was shipped in the frozen repository, the version locking would be broken if you were to succeed. To prevent the breakage from happening, your OS'es Package Manager prevents this.

Read my answer to find out how I overcame $Z

eyoung100
  • 6,252
  • 23
  • 53
  • If user's are going to Downvote this, please leave a few comment's, so I can attempt to "fix" what it's being downvoted for. Thanks! – eyoung100 Jan 26 '24 at 20:04
  • You can have as many versions of gcc as you want, installed at the same time. Example https://stackoverflow.com/questions/47175706/how-to-install-gcc-4-9-2-on-rhel-7-4/47189915#47189915 – Knud Larsen Jan 26 '24 at 22:22
  • @KnudLarsen: Whilst I agree with that in theory, as I have multiple compilers on my gentoo box, I wrote this question because users end up with a broken system, after trying to install an upgraded or downgraded system-wide compiler without using their package manager, or trying to compile an older version with newer required libraries, or a newer version with older libraries. in the link you provided, all of those installs are managed via yum – eyoung100 Jan 26 '24 at 22:31
  • Using internal {gmp, mpfr, mpc} objects compiled into the executable gcc will usually avoid dependency issues https://stackoverflow.com/questions/58859081/how-to-install-an-older-version-of-gcc-on-fedora/58920302#58920302 ..... gcc - configure https://docs.google.com/document/d/1UxUOwTqZk9p9vbHffgIqxWWey6TU1HuMyCCTC9Htvj8/edit?usp=drive_link – Knud Larsen Jan 26 '24 at 22:42
  • @KnudLarsen I'm not discounting anything your telling me, but I'm saying the users and readers who come here with this issue are usually frustrated or upset after trying multiple compile attempts etc., and most of them have never compiled anything. They aren't going to know about "internal objects compiled into the executable" given this may be the first compile they've decided to try. I'm not trying to pick a fight. I'm attempting to provide a solution that works. If users decide to follow it great, if not that's great too. Either way the procedure is here and documented. – eyoung100 Jan 26 '24 at 22:52
  • @KnudLarsen If you want to write up a question and answer involving objects compiled into the gcc executable, feel free to do just that, as I felt like writing this question and answer yesterday – eyoung100 Jan 26 '24 at 22:57
  • Generally speaking, distribution variants marked as "edge", "rolling release" or "testing" are more suitable for programming, because they contain the latest software. "Stable" or "LTS" versions contain packages which are older, but stable for general use, and might not be suitable for programming. – Vilinkameni Jan 27 '24 at 06:39

2 Answers2

2

A less heavyweight solution is to use containers. Install Docker or Podman, and follow the recipe in eyoung100’s answer to identify the distribution release you’re after, or look it up on Repology.

Using the same Fedora 36 example, run a container:

podman run -it fedora:36

You can add -v options to make directories on your system available inside the container:

podman run -it -v ~/myproject:/myproject:z fedora:36

(only add :z if you‘re using SELinux).

In the container, install gcc and any other tools you need, build your project (in /myproject), and you’ll find your files in the directory you shared.

Stephen Kitt
  • 434,908
1

My Solution

First off, I guess I would be considered a purist in that if a package isn't in your repository, or can't be added from a third party repository, you shouldn't attempt to compile it from scratch or "force it to work" because doing so short-circuits your package manager. With that in mind, I present a rock-solid solution


Virtualization Is Our Friend

We need some tools and a bit of Hard Drive Space for this approach. I'll leave making space available to you but aside from that follow these steps:

  1. Install VirtualBox with your package manager
  2. Install Vagrant with your package manager

Note: Vagrant will work with Hyper-V and docker out of the box I believe (see Stephen Kitt's answer for help with docker), but I chose VirtualBox because that's what I learned first, and if needed I can install a Desktop in the VM to configure the VM further.

With our Virtualization Helpers installed we can continue. I'm continuing by:

  1. Gathering Requirements - I came up as a web programmer, so let's gather requirements from our customer. For our purposes, I'm going to fill in $Z now. Using Example question 2 from the Issue heading above we have the following values:
    • $X = Fedora
    • $Y = 13.2.1-6.fc39
    • $Z = 12.x.x
  2. Always use the following sentence as the Search term in your favorite engine: Which release of $X contained GCC $Z

So using our example: Which release of Fedora contained GCC 12. Now Quoting Google:

Update the Fedora 36 GNU Toolchain to gcc 12 and glibc 2.35. The gcc 12 is currently under development and will be included in Fedora 36 upon release. Feb 16, 2022

  1. Let's check to see if the above release - 36 - is still supported. In our search engine:
    $X release history

Which would equate to Fedora release history in our example, which gives us Fedora Linux release history. Well, what do we do now? It looks like Fedora 36 is no longer supported. We added Vagrant for this very reason. If we visit The Vagrant Cloud, we can search for Fedora 36, which yields these results, and using a Vagrantfile, we can customize a full VM version and develop our application or website using the VM while saving our project files on our host system.

Reason Why I Chose This Approach

Using virtualization separates your development environment from the system you use day-to-day, and keeps you from making an irreparable mistake. I realize it will cost a bit of extra setup time, but Vagrant only needs to be installed once. A vagrantfile only needs to be created each time your project requirements change. The small learning curve for Vagrant and the Virtualization is worth the tradeoff of reinstalling an OS if a mistake is made trying to figure out how to install multiple compilers.

eyoung100
  • 6,252
  • 23
  • 53