1

I installed the devtoolset-4 software collection on a CentOS 7 machine that I'm using for development. This software collection includes the compiler I want to use, g++ 5.2.1, as well as Eclipse CDT 4.5 (Mars). When I create a new c++ project in Eclipse and navigate to the project properties (right click on project, then Properties -> C/C++ Build -> Environment) I can see that Eclipse has created a PATH environment variable that gets appended to the current PATH when building my project. The value of the Eclipse-defined PATH is:

/bin:/opt/rh/devtoolset-4/root/usr/bin:/opt/rh/rh-java-common/root/usr/bin:/usr/lib64/qt-3.3/bin:/home/kts/perl5/bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/sbin:/home/kts/.local/bin:/home/kts/bin

The first entry in the PATH is /bin, which on CentOS 7 is a symlink to /usr/bin. In /usr/bin is the g++ 4.8.5 binary that gets installed from the official CentOS repositories. This results in Eclipse building my project with g++ 4.8.5 instead of the version I actually want it to use, which is the g++ 5.2.1 binary sitting in the /opt/rh/devtoolset-4/root/usr/bin directory (second entry in PATH). If I remove the /bin entry from the Eclipse PATH variable my project then builds with the desired g++ 5.2.1.

I'm a little hesitant to rely on this fix moving forward though, as I expected that projects created in the version of Eclipse that is included in devtoolset-4 would work out of the box with the version of g++ included in devtoolset-4. Has anyone else run into this problem? Is there something I'm not doing correctly in my use of the devtoolset-4 software collection? Or is this a bug? Any insight is greatly appreciated.

unbrokenrabbit
  • 301
  • 4
  • 12

1 Answers1

0

Typically, when there are multiple versions of g++ installed, there are suffixed versions of the g++ executable - e.g. g++-4.8, g++-5 - available so that you can choose the version you want by using the appropriate suffix. You can verify that this is the case by running g++-5 in a shell (with the PATH set up appropriately) and seeing if it is resolved.

Assuming this is the case, you just need to configure Eclipse to use g++-5 instead of plain g++. You can do this in Project Properties -> C/C++ Build -> Settings -> Tool Settings. Under each of "GCC C++ Compiler", "GCC C Compiler", and "GCC C++ Linker", change the "Command" from g++ or gcc to g++-5 or gcc-5.

Note that GCC has recently changed their version numbering. While previously, annual releases would only increment the second version number (4.7, 4.8, 4.9), from version 5 onwards every annual release increments the first version number. Accordingly the suffix for versions 5 and later is just the one number, e.g. g++-5, not g++-5.2 (whereas previously it would be g++-4.8, g++-4.9 etc.).

HighCommander4
  • 50,428
  • 24
  • 122
  • 194
  • I appreciate the suggestion, but I'm not seeking an answer as to how to specify the version of g++ that Eclipse uses for builds. My concern is about whether or not it is intended behavior for the version of Eclipse CDT installed as a part of the devtoolset-4 software collection to create projects that default to using a version of g++ that is different than the one that also gets installed as a part of the devtoolset-4 software collection. The Eclipse CDT installation gets launched via: scl enable devtoolset-4 eclipse, which gives the expectation of using g++ 5.2.1. But this is not the case. – unbrokenrabbit May 10 '17 at 03:11
  • @unbrokenrabbit: My guess is the devtoolset-4 packagers didn't take any steps to customize the compiler command that CDT uses, so it just uses the default "g++", which will resolve to whatever g++ is first in your PATH. – HighCommander4 May 10 '17 at 07:14