How to switch the version of arm-linux-gnueabihf-gcc?
You can run arm-linux-gnueabihf-gcc-5
instead of gcc
.
This file list includes the names of the other tools the gcc-5-arm-linux-gnueabihf
package places in /usr/bin
, which you may find useful. (You didn't mention what release you're running but I'm guessing it's 18.04, since that release is a popular LTS and it defaults to version 7.)
Note that even if you wanted to use the default version, unless you've changed what /usr/bin/gcc
points to (which I don't recommend), the gcc
command is running a GCC compiler that generates native executables. This won't be an ARM compiler unless your Ubuntu system is running on ARM. To run the default version of the GCC cross compiler for armhf, use arm-linux-gnueabihf-gcc
(and see this file list).
Multiple versions of both native and cross compilers can be installed on the same system at the same time. Only the default version of the native GCC compiler is typically invoked with the gcc
command, however. Other commands have a toolchain prefix, a version suffix, or (in this case) both. This is the case even when that non-default compiler is the only compiler installed on the system.
If you really must make gcc
call that compiler...
If you need gcc
to call that compiler because some other build tool, like make
is calling gcc
, the best approach is usually to reconfigure that other tool or to set the CC
environment variable to the compiler you want. Just making gcc
run the compiler you need may also not be sufficient, because the names of other tools will still run the native versions.
With that said, assuming your your Ubuntu system is not an armhf system but you still really want gcc
to run the arm-linux-gnueabihf-gcc-5
cross compiler, you have a few options. You could replace the /usr/bin/gcc
symlink (which on 18.04 links to gcc-7
), but I recommend against that. Doing that is likely to break anything that assumes gcc
is a native compiler, and may either interfere with or be undone by future package management operations.
Instead, you could put a gcc
symlink to arm-linux-gnueabihf-gcc-5
in your user's private bin directory ~/bin
. The default per-user ~/.profile
file adds that directory to $PATH
when you log in, if the directory exists. Automated builds (like when you run ./configure
or cmake ..
and then make
) that you don't customize usually use cc
, which will continue to be a symlink to a native compiler, so this shouldn't break things.
Personally, I would not want to do even this, because I would myself become confused. I prefer that it always be immediately clear what platform my compiler targets, when it is a cross compiler.
Related videos on Youtube
Comments
-
Paul Bernhard Wagner over 1 year
I would like to use version 5 of
arm-linux-gnueabihf-gcc
.So I installed it via:
apt-get install gcc-5-arm-linux-gnueabihf
But now when I do
gcc --version
it will tell me it's version 7.How do I tell it to use the older version?
Or do I have to uninstall the newer version completely?