2

I'm currently setting up Homebridge to run on my Pi using this installation guide.

I have run into a problem regarding the C++ compiler section; I understand that this part of the guide is out of date as the versions in the instructions to not match the linked guide. However, whilst I have successfully followed the other guide and can now execute gcc-8.1.0 --version to receive:

gcc-8.1.0 (GCC) 8.1.0
Copyright (C) 2018 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.

When I run either g++ -v or gcc -v I receive the following:

...
gcc version 6.3.0 20170516 (Raspbian 6.3.0-18+rpi1+deb9u1) 

This is contrary to the main guide which dictates that both g++ -v and gcc -v should yield the same version as the one installed first (version 8.1.0 not 6.3.0).

Whilst the main guide does indicate that this may be the case by stating that:

Now you have the needed compiler, but it is not yet set to be the default compiler. You can fix that using the instructions here.

In my case I simply did this:

sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.9 60 --slave /usr/bin/g++ g++ /usr/bin/g++-4.9

sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.6 40 --slave /usr/bin/g++ g++ /usr/bin/g++-4.7

This does not help considering the versions do not match.

My question is: Do I need to change both the default g++ and gcc versions considering that g++ and gcc already seem to be preinstalled? If so, what command(s) do I need to issue to do this?

Thank you in advance for your help,

Kind regards, Rocco

1

In the main guide says

Now you have the needed compiler, but it is not yet set to be the default compiler. You can fix that using the instructions here.

If you read the link, it says that after you let your system know that there is an other gcc compiler version

sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-8.1.0 60 --slave /usr/bin/g++ g++ /usr/bin/g++-8.1.0

Then you can use the commands

sudo update-alternatives --config gcc
sudo update-alternatives --config g++

to select the default compilers


EDIT

Let me explain you a little what is going on so that you can understand your problem.

When you try to run a command like gcc --version your system searches the paths inside the environment PATH variable (windows has one too) to find that program. That variable has the path /usr/bin inside it, so it checks if there is a programmed called gcc on /usr/bin/gcc. You can see your path variable by running echo $PATH.

Since gcc comes in many versions, the /usr/bin/gcc file is not the actual binary, it is a symlink (something like the shortcuts on the Windows OS) that points to the actual binary (for example /usr/bin/gcc points to /usr/bin/gcc-6.3.0. You can create a symlink by runningln -sf /path/to/file /path/to/symlink` (similar question here)

In your system the gcc-6.3.0 is installed as the default compiler. This means that the first gcc programmed found on the paths of PATH points to the gcc-6.3.0 binary.

Since you want when you call the gcc the gcc-8.1.0's binary to be called, what you have to do is make sure that the first gcc binary found on the paths of PATH is the gcc-8.1.0's binary.

In my raspberry pi the path variable is /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin thus the /usr/local/bin folder will be checked every time before the /usr/bin (your's would be the same).

So what you will have to do is create a the /usr/local/bin/gcc symlink. You can do that be running ln -s /usr/local/gcc-8.1.0 /usr/local/bin/gcc

  • Thank you for your answer. I had seen that link but I was unaware of how exactly I would adapt those commands to work with the 8.1.0 version – Rocco Jan 28 at 7:04
  • Sorry to bother you, just tried out the first command and got the following error update-alternatives: error: alternative path /usr/bin/gcc-8.1.0 doesn't exist. I have a feeling this is because the guide installs it to /usr/local rather than /usr/bin. How exactly would I need to edit the first command? Or should I simply move where the installation installs the package? Thanks! – Rocco Jan 31 at 18:18
  • Check my edited answer so that you can understand your problem. If you have questions maybe I can answer them. – GramThanos Jan 31 at 22:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.