Difference between pages "Switching gcc" and "Talk:Switching gcc"

(Difference between pages)
(Changing Default gcc)
 
 
Line 1: Line 1:
 +
== conceptual tweaks ==
  
== How to switch the gcc version for a specific task ==
+
I made some changes here because our kernel ebuilds that require 4.4.5 use it automatically and do not require gcc-config steps. But I wanted to preserve the information you added. I also suggested that people use <tt>gcc-4.4.5</tt> directly rather than use <tt>gcc-config</tt> if possible, since this is a local change. -Daniel
  
This article describes how you can switch the [http://en.wikipedia.org/wiki/GNU_Compiler_Collection gcc] version.
+
Hi Daniel, thank you for your tweaks! I added this article, since I emerged the current rhel6-stable Kernel (2.6.32-042stab059.7) and ran into the described problems. Also, I did this without "binary" USE-Flag, since (although this isn't recommended) we change the Kernel's config by activating /proc/config.gz (if not activated by default) because of our factory's policy. Using genkernel manually is the more comfortable way for us.
Let's assume, you want to use gcc-4.4.5, but your main [http://en.wikipedia.org/wiki/GNU_Compiler_Collection gcc] version is 4.6:
+
I ran into the described problems (which you removed from Revision of 11:32, 14 August 2012) only Oleg could give me the hint for GCC 4.4.5 and we realized that this info about how to switch gcc was still missing in the wiki. When emerging the kernels without binary USE-Flag, gcc v4.4.5 is emerged as dependency of that kernel, but sorry: It seems as if gcc is *not* used by genkernel automatically. So, even though the binary USE-Flag is recommended, it doesn't read as a must in the docs (and thanks to genkernel it isn't). I think that we cannot assume the gcc-4.4.5 is always "used automatically". Building a kernel with genkernel seems like a valid alternative to me; but in this case you need these informations.
 +
You further wrote that "gcc-config" is a local change and so not a perfect solution: That's why I added the "fancyimportant" - warning :P
 +
Do not get me wrong: I *really* appreciate your help! But don't you think these points / alternate way has to be taken in account too? -Marc (Judge/Whitewolf Fox)
  
<console>
+
That should have never happened, because all openvz kernels using gcc-4.4.5 patch, so you even shouldn't know about gcc-config. Somehow, when testing new 059.7 ebuild, i missed the patch, my fault. Anyway gcc-config is forked in funtoo and it's good to have a wiki page.
# ##i##gcc --version
+
gcc (Gentoo 4.6.2-r1 p1.4, pie-0.5.0) 4.6.2
+
Copyright (C) 2011 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.
+
</console>
+
 
+
So - what to do? The best and safest way is to switch your [http://en.wikipedia.org/wiki/GNU_Compiler_Collection gcc] version temporarily to the same version that is used by the upstream project.
+
 
+
To do that, we use the tool gcc-config. First, we'll have a look on what versions are available on your system. Install the desired version of [http://en.wikipedia.org/wiki/GNU_Compiler_Collection gcc] explicitly:
+
 
+
<console>
+
# ##i##emerge =sys-devel/gcc-4.4.5*
+
</console>
+
 
+
After emerging, you can see that it is installed with <tt>gcc-config</tt>:
+
 
+
<console>
+
# ##i##gcc-config --list-profiles
+
[1] x86_64-pc-linux-gnu-4.4.5
+
[2] x86_64-pc-linux-gnu-4.6.2 *
+
#
+
</console>
+
 
+
This list shows the versions of gcc that are now installed. The new compiler is now available and can be called as <tt>gcc-4.4.5</tt>. But the default system compiler (what you get when you call <tt>gcc</tt>) is set to 4.6.2. Like with other Funtoo tools, the asterisk marks the currently active version of gcc.
+
 
+
If possible, it is best to modify Makefiles and change the <tt>CC</tt> variable to force any required sources to use <tt>gcc-4.4.5</tt> instead of <tt>gcc</tt> to build. This is a non-invasive change that will be local to your current project, which is the preferred way to make these types of build changes. This is the mechanism we use for building Enterprise kernels that build cleanly with earlier versions of gcc.
+
 
+
== Changing Default gcc ==
+
 
+
Again, this is not recommended as it will affect the default <tt>gcc</tt> version that the entire system will use. Use this with caution. It is also not supported to run Funtoo Linux with a non-standard system compiler, sicne we are not testing it.
+
 
+
Before you switch your [http://en.wikipedia.org/wiki/GNU_Compiler_Collection gcc] version, it is very important that you make a note about what version was the active one before, so you can easily switch it back to the profiles default after you're done.
+
 
+
To switch the version to 4.4.5, we make use of gcc-config again. You can define the version you want to switch to either by giving the number printed before the listed version in the output of <code>gcc-config --list-profiles</code> or by entering the whole string. So, giving <code>1</code> or <code>x86_64-pc-linux-gnu-4.4.5</code> to gcc-config leads to the same result:
+
 
+
<console>
+
# ##i##gcc-config 1
+
* Switching native-compiler to x86_64-pc-linux-gnu-4.4.5 ...
+
>>> Regenerating /etc/ld.so.cache...                                                                            [ ok ]
+
 
+
* If you intend to use the gcc from the new profile in an already
+
* running shell, please remember to do:
+
 
+
*  # source /etc/profile
+
#>
+
</console>
+
 
+
Like it's already suggested in the output from above, the next and last step is to refresh your environment to make use of this switch. You may either issue the following two commands or open another login shell for this. No matter what you do, you should verify that the active [http://en.wikipedia.org/wiki/GNU_Compiler_Collection gcc] version is the one you wanted to switch to:
+
 
+
<console>
+
# ##i##gcc --version
+
gcc (Gentoo 4.6.2-r1 p1.4, pie-0.5.0) 4.6.2
+
Copyright (C) 2011 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.
+
 
+
# ##i##source /etc/profile
+
# ##i##env-update
+
>>> Regenerating /etc/ld.so.cache...
+
# ##i##gcc --version
+
gcc (Gentoo 4.4.5 p1.3, pie-0.4.5) 4.4.5
+
Copyright (C) 2010 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.
+
 
+
#
+
</console>
+
 
+
As you see here, the current shell is using [http://en.wikipedia.org/wiki/GNU_Compiler_Collection gcc] version 4.4.5 only after you have refreshed your environment. Now you can build your packages / source which need this specific version of [http://en.wikipedia.org/wiki/GNU_Compiler_Collection gcc].
+
 
+
It is important that you reset the [http://en.wikipedia.org/wiki/GNU_Compiler_Collection gcc] version back to the default of your profile. To do that, simply reply the above steps again but this time, use your profile's default version of [http://en.wikipedia.org/wiki/GNU_Compiler_Collection gcc] to switch to.
+

Latest revision as of 05:03, August 15, 2012

conceptual tweaks

I made some changes here because our kernel ebuilds that require 4.4.5 use it automatically and do not require gcc-config steps. But I wanted to preserve the information you added. I also suggested that people use gcc-4.4.5 directly rather than use gcc-config if possible, since this is a local change. -Daniel

Hi Daniel, thank you for your tweaks! I added this article, since I emerged the current rhel6-stable Kernel (2.6.32-042stab059.7) and ran into the described problems. Also, I did this without "binary" USE-Flag, since (although this isn't recommended) we change the Kernel's config by activating /proc/config.gz (if not activated by default) because of our factory's policy. Using genkernel manually is the more comfortable way for us. I ran into the described problems (which you removed from Revision of 11:32, 14 August 2012) only Oleg could give me the hint for GCC 4.4.5 and we realized that this info about how to switch gcc was still missing in the wiki. When emerging the kernels without binary USE-Flag, gcc v4.4.5 is emerged as dependency of that kernel, but sorry: It seems as if gcc is *not* used by genkernel automatically. So, even though the binary USE-Flag is recommended, it doesn't read as a must in the docs (and thanks to genkernel it isn't). I think that we cannot assume the gcc-4.4.5 is always "used automatically". Building a kernel with genkernel seems like a valid alternative to me; but in this case you need these informations. You further wrote that "gcc-config" is a local change and so not a perfect solution: That's why I added the "fancyimportant" - warning :P Do not get me wrong: I *really* appreciate your help! But don't you think these points / alternate way has to be taken in account too? -Marc (Judge/Whitewolf Fox)

That should have never happened, because all openvz kernels using gcc-4.4.5 patch, so you even shouldn't know about gcc-config. Somehow, when testing new 059.7 ebuild, i missed the patch, my fault. Anyway gcc-config is forked in funtoo and it's good to have a wiki page.