Difference between pages "Switching gcc" and "Install/fr/Finish"

(Difference between pages)
(Changing Default gcc)
 
(Étapes de finalisation)
 
Line 1: Line 1:
 +
=== Finalisation et redémarrage ===
  
== How to switch the gcc version for a specific task ==
+
[[Category: Installation Guide Parts]]
 
+
This article describes how you can switch the [http://en.wikipedia.org/wiki/GNU_Compiler_Collection gcc] version.
+
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:
+
 
+
<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.
+
</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.
+

Revision as of 17:36, January 4, 2015

Finalisation et redémarrage