2

I am working on RHEL 6.7 that comes with GCC 4.4.7 and would like to upgrade GCC to 4.9.2 that comes with devtoolset-3. I am using cmake to compile my C++ code.

The devtoolset-3 that is provided by Red Hat installs the new GCC under :

/opt/rh/devtoolset-3/root/usr/bin/

I would like to use the new compiler, GCC 4.9.2 to compile my code but the binary has to work on a "vanilla" RHEL 6.7 installation so I am trying to link the binary with the standard libraries shipped with this version of RHEL, that come from GCC 4.4.7 (libstdc++.so.6.0.13).

I have added these lines to CMake:

set(CMAKE_C_COMPILER "/opt/rh/devtoolset-3/root/usr/bin/cc")
set(CMAKE_CXX_COMPILER "/opt/rh/devtoolset-3/root/usr/bin/c++")

I had some link problems for missing libraries so I had to add some parameters to GCC command line:

set(COMPILER_UPGRADE_FLAGS "-pthread -luuid -I/usr/include/c++/4.4.7/")
set(CMAKE_CXX_FLAGS_DEBUG "....... {COMPILER_UPGRADE_FLAGS}")

After these changes I was able to compile my code. However, I was getting a segmentation fault when running my unit tests. After some debugging, I found out that the binary was correctly linked to the C++ library shipped with RHEL 6.7 but the code was compiled with the wrong include files, the ones in :

/opt/rh/devtoolset-3/root/usr/include/c++/4.9.2/

To avoid this problem, I thought I would make GCC use the header files that come with the original version of the library so I have added this command line option to GCC:

-I/usr/include/c++/4.4.7/

However, after doing this I am not able to compile my program anymore and I incur in a lot of errors like this:

/usr/include/c++/4.4.7/bits/stl_function.h:711:64: error: operator '||' has no right operand
#if !defined(__GXX_EXPERIMENTAL_CXX0X__) || _GLIBCXX_DEPRECATED

At this point I am kind of blocked and would like to know if somebody can help me. Is what I am trying to do even possible?

Perennialista
  • 628
  • 1
  • 8
  • 19
  • 6
    Short answer: no, it's not possible. The chances of a compiling C++ code with gcc 4.9, and have it successfully link with gcc 4.4's libstdc++ may not exactly be a mathematical zero, but practically equivalent to it. P.S. This goes, pretty much, for any other C++ too, in an analogous situation. – Sam Varshavchik Jun 09 '17 at 00:14
  • FWIW, in [the exact same situation](https://stackoverflow.com/q/38769843/560648) I ended up [just redistributing](https://stackoverflow.com/a/38784548/560648) [the newer _libstdc++_ and _libgcc_s_](https://stackoverflow.com/q/39001658/560648) (and being careful that they get picked at runtime on the target machine, with a `-Wl,-rpate,'$ORIGIN'`). Works great. – Lightness Races in Orbit Jun 09 '17 at 01:09
  • Thank you both for your comments, as I understand I will have to find another way to distribute our application. I am puzzled by the ["3.2.4 C++ Compatibility" section of the devtoolset, version 3](https://access.redhat.com/documentation/en-US/Red_Hat_Developer_Toolset/3/html/User_Guide/sect-GCC-CPP.html). This states: Objects compiled with Red Hat Developer Toolset 2 and Red Hat Developer Toolset 3 in C++98 mode (the default mode) are compatible with each other, and with objects compiled with the Red Hat Enterprise Linux system compilers in C++98 mode. – Perennialista Jun 09 '17 at 15:54

0 Answers0