'g++: error: unrecognized '-std=c++17' (what is g++ version and how to install)
I am working on RHEL 7.5 and trying to compile a uWebSocket (This exaple) code. I clone the project and open it. When I start make on Makefile I got this error;
BroadcastingEchoServer uSockets/*.o -lz;
g++: error: unrecognized command line option '-std=c++17'
make: [examples] Error 1>
The main problem is -std=c++17 is not recognized. How can I control what c++ version I have (that 17 in the end) and how can I install required version.
gcc --version
gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-39)
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Thanks
Solution 1:[1]
RHEL is providing newer versions of GCC additionally using socalled Software Collections (SCL). In your case you could enable this repository (depending whether you have a workstation or a server subscription):
subscription-manager repos --enable rhel-server-rhscl-7-rpms
subscription-manager repos --enable rhel-workstation-rhscl-7-rpms
Afterwards you could install one (or multiple) of the following packages:
yum install devtoolset-6-gcc-c++
(GCC 6.3.1, until RHEL 7.7)yum install devtoolset-7-gcc-c++
(GCC 7.3.1)yum install devtoolset-8-gcc-c++
(GCC 8.3.1)yum install devtoolset-9-gcc-c++
(GCC 9.3.1, since RHEL 7.7)yum install devtoolset-10-gcc-c++
(GCC 10.2.1, since RHEL 7.9)yum install devtoolset-11-gcc-c++
(GCC 11.2.1, since RHEL 7.9)
Note that you can install the whole devtoolset of a specific version using e.g. yum install devtoolset-11-toolchain
. This might be needed (or not) depending on your specific usecase.
Once installed, run e.g. scl enable devtoolset-11 bash
when you installed devtoolset-11-gcc-c++
. Calling g++
will then lead to GCC 11.2.1. For scripts, using . /opt/rh/devtoolset-11/enable
before using g++
might be more convenient.
If needed, see How can I make a Red Hat Software Collection persist after a reboot/logout? in the Red Hat Knowledgebase.
Solution 2:[2]
gcc (GCC) 4.8.5
C++17 is not supported by GCC v4.8.
C++17 is not supported by GCC v4.9.
C++17 is supported by GCC v5, but you need
-std=c++1z
:The next revision of the ISO C++ standard, tentatively planned for 2017. Support is highly experimental, and will almost certainly change in incompatible ways in future releases.
GCC v5 was released 2015 and they did not yet have time machines back then ;o)
Same applies to GCC v6 and GCC v7 (released 2016 and 2017).
C++17 is supported by GCC v8 by means of
-std=c++17
(and by-std=c++1z
which is deprecated since then).
For the GNU-C++ dialects, use -std=gnu++*
instead of -std=c++*
.
Hence for serious projects, you should use GCC v8 or newer.
Solution 3:[3]
Use:
yum install devtoolset-9-toolchain
scl enable devtoolset-9 bash
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | |
Solution 2 | emacs drives me nuts |
Solution 3 | Pedro Lobito |