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?