4

I have installed the devtoolset-10 package on CentOS 7 and run the /opt/rh/devtoolset-10/enable script so that now when I do this:

g++ --version

I get this:

g++ (GCC) 10.2.1 20210130 (Red Hat 10.2.1-11)

Great. Trouble is, the headers under /usr/include/c++ still point to ye olde libstdc++-4.8.5. That is, if I do ls in /usr/include/c++, all I see is:

bash-4.2$ ls /usr/include/c++
4.8.2  4.8.5

What is the magic incantation to "enable" libstdc++-10 to be the default system C++ stdlib?

Eric Niebler
  • 5,927
  • 2
  • 29
  • 43

4 Answers4

3

devtoolset-10

Every g++ comes with it's own headers. /usr/include/c++/4.8* is for 4.8.5 only.

devtoolset-10: g++ version 10 is using the headers at /opt/rh/devtoolset-10/root/usr/include/c++/10

"enable" libstdc++-10

There is no shared library "libstdc++-10". There is /opt/rh/devtoolset-10/root/usr/lib/gcc/x86_64-redhat-linux/10/{ libstdc++.a, libstdc++.so } , where libstdc++.so is a ~200B text file.

Knud Larsen
  • 5,753
  • 2
  • 14
  • 19
  • So if you want to to tell e.g. cmake to reference headers in c++/10 as opposed to c++/4.8, export `CXX` env var [per below](https://stackoverflow.com/a/73558575/1080804) – ecoe Aug 31 '22 at 15:48
  • @ecoe → Selecting header version. That's easy, just set the preferred 'g++' for cmake, with e.g. `$ CC=g++73 CXX=g++73 cmake ..` ... and the "version 7.3" headers will be used. ... Ref. extra gcc/g++ https://stackoverflow.com/questions/47175706/how-to-install-gcc-4-9-2-on-rhel-7-4/47189915#47189915 – Knud Larsen Aug 31 '22 at 18:20
1

I guess the users are supposed to query gcc for the include path. On my CentOS /usr/include/c++ is not a symlink, and is not supposed to point anywhere, but one can work around that using update-alternatives (I did that only for the compiler itself only, though). Might be overriden by an update, but those don't happen often enough on CentOS.

SD57
  • 73
  • 7
1

What is the magic incantation to "enable" libstdc++-10 to be the default system C++ stdlib?

Developer Toolset uses a hybrid linkage model. This means that it does not come with its own libstdc++.so.6, but uses the system version as far as possible. The missing parts are linked statically. This is achieved by the linker script that Knud Larsen mentions.

Florian Weimer
  • 32,022
  • 3
  • 48
  • 92
0

If you want to compile using headers from the latest C++ compiler you have on Centos7:

  1. Remove your build directory
  2. Export your chosen compiler specifically: export CXX=g++

Thanks to this comment from github:

ecoe
  • 4,994
  • 7
  • 54
  • 72