title: How to use a new G++ compiler to link to and old libstdc++
body: <p>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.</p>
  
  <p>The devtoolset-3 that is provided by Red Hat installs the new GCC under :</p>
  
  <blockquote>
    <p>/opt/rh/devtoolset-3/root/usr/bin/</p>
  </blockquote>
  
  <p>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 (<strong>libstdc++.so.6.0.13</strong>). </p>
  
  <p>I have added these lines to CMake:</p>
  
  <pre><code>set(CMAKE_C_COMPILER "/opt/rh/devtoolset-3/root/usr/bin/cc")
  set(CMAKE_CXX_COMPILER "/opt/rh/devtoolset-3/root/usr/bin/c++")
  </code></pre>
  
  <p>I had some link problems for missing libraries so I had to add some parameters to GCC command line:</p>
  
  <pre><code>set(COMPILER_UPGRADE_FLAGS "-pthread -luuid -I/usr/include/c++/4.4.7/")
  set(CMAKE_CXX_FLAGS_DEBUG "....... {COMPILER_UPGRADE_FLAGS}")
  </code></pre>
  
  <p>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 : </p>
  
  <blockquote>
    <p>/opt/rh/devtoolset-3/root/usr/include/c++/4.9.2/</p>
  </blockquote>
  
  <p>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:</p>
  
  <pre><code>-I/usr/include/c++/4.4.7/
  </code></pre>
  
  <p>However, after doing this I am not able to compile my program anymore and I incur in a lot of errors like this:</p>
  
  <blockquote>
    <p>/usr/include/c++/4.4.7/bits/stl_function.h:711:64: error: operator
    '||' has no right operand<br>
    #if !defined(__GXX_EXPERIMENTAL_CXX0X__) ||
    _GLIBCXX_DEPRECATED</p>
  </blockquote>
  
  <p>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?</p>