As of ubuntu 17.10, apt source has provided us several cross-compile toolchains for the ARM platform:
- gcc-5-arm-linux-gnueabihf
- gcc-6-arm-linux-gnueabihf
- gcc-7-arm-linux-gnueabihf
- …
After getting them installed, these tools got a suffix number to indicate the version, like /usr/bin/arm-linux-gnueabihf-gcc-5
.
We’d like to specify which one to use as per the project requirement.
Fortunately we can make it easily by using the tool update-alternatives
which comes with the ubuntu distribution.
1 | $ sudo update-alternatives --install /usr/bin/arm-linux-gnueabihf-gcc arm-linux-gnueabihf-gcc /usr/bin/arm-linux-gnueabihf-gcc-5 100 --slave /usr/bin/arm-linux-gnueabihf-g++ arm-linux-gnueabihf-g++ /usr/bin/arm-linux-gnueabihf-g++-5 |
Here, we have provided the arm-linux-gnueabihf-gcc
as the master and arm-linux-gnueabihf-g++
as slave. Multiple slaves can be appended along with master. When master symbolic link is changed, the slaves will be changed too.
Pass the second version of these tools to be recorded:1
$ sudo update-alternatives --install /usr/bin/arm-linux-gnueabihf-gcc arm-linux-gnueabihf-gcc /usr/bin/arm-linux-gnueabihf-gcc-6 50 --slave /usr/bin/arm-linux-gnueabihf-g++ arm-linux-gnueabihf-g++ /usr/bin/arm-linux-gnueabihf-g++-6
Now you can switch between these versions by using:1
$ sudo update-alternatives --config arm-linux-gnueabihf-gcc