I had a Backtrack user on IRC today asking about using different versions of GCC in Backtrack. Since Backtrack is based on Ubuntu Linux this article will apply to any version of Ubuntu but I wanted to write something specifically for Backtrack users. There are many reasons for needing different versions of GCC and G++. One of the main ones is installing a program which requires a kernel module to be built. What happens is that if the kernel was built with GCC-4.1 and GCC has since been updated to GCC-4.3 sometimes the build will fail dude to a kernel/GCC –version mismatch. Below I detail the steps to downgrade from GCC-4.3 to GCC-4.1 on Backtrack Linux.
The first step is to check your GCC version:
Since G++ and GCC version need to match we will also be downgrading G++
You can check the G++ version the same way:
As you can see from the screen shots we are using GCC and G++ version 4.3.2. For the sake of this article we will be downgrading to 4.1
The first thing to do is install GCC 4.1:
And likewise G++ 4.1:
Okay, so that part is fairly simple. The tricky part is that when you issue the command GCC it is actually a sybolic link to which ever version of GCC you are using. What this means is we can create a symbolic link from GCC to whichever version of GCC we want.
You can see the symbolic link in this picture:
And here is the screen shot showing G++:
So what we need to do is remove the GCC symlink and the G++ symlink and then recreate them linked to GCC 4.1 and G++ 4.1:
Now if we check the symbolic links again we will see GCC & G++ are now linked to GCC 4.1 and G++ 4.1:
Finally we can check our GCC -v again and make sure we are using the correct version:
Thats all there is to switching the versions. Something for a future post maybe to write a short script which will allow you to choose between all of the installed versions. I will save that for a rainy day though.
Thank You for this information! Saved the day.
Thanks for the feedback, we always feel good when we have helped someone out.