When I run g++ --version on in my Cloud9 terminal I get g++ (GCC) 4.4.7 20120313 (Red Hat 4.4.7-3). This is a fairly old version - old enough that when I try to use C++11 library features like std::unordered_set, I get: "This file requires compiler and library support for the upcoming ISO C++ standard, C++0x. This support is currently experimental, and must be enabled with the -std=c++0x or -std=gnu++0x compiler options."
I'm not really okay with this, because I don't like having to worry about what features I'm allowed to use and which ones I need to avoid. So I went looking around for how to update g++ to the latest stable version (which seems to be 4.8.1 as of this writing), but I can't figure out how to do it. I tried apt-get, but I just got an error: "Sorry, apt-get is not supported on this system. Try c9pm instead.". Well I tried that, but c9pm list (which is supposed to "List available packages") doesn't show anything that looks like g++. So I'm lost.
How do I install g++ 4.8.1 on Cloud9?
When I run lsb_release -a I see that Cloud9 IDE currently runs on "Red Hat Enterprise Linux Server release 6.4 (Santiago)".
If you choose C/C++ as the project type for a new project you will get a newer gcc version (currently 4.7.2). If you need an even newer one let us know and we can update that version. You can always try to compile the tools you need on the workspace but in case of gcc this might take ages.
This is no longer a problem. g++ --version now returns g++ (Ubuntu 4.8.2-19ubuntu1) 4.8.2 which, to my knowledge, has full support for C++11.
Actually, cloud9 gives you 4.8.2
cpp --version
cpp (Ubuntu 4.8.2-19ubuntu1) 4.8.2
Copyright (C) 2013 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.
Related
I was trying to activate the option -Wmismatched-tags on gcc (detect inconsistent class/struct declaration, which might happens when using forward declaration), but on Ubuntu I get
c++: error: unrecognized command line option '-Wmismatched-tags'
My gcc version:
# gcc --version
gcc (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0
Copyright (C) 2019 Free Software Foundation, Inc.
Looking here it seems like it was integrated in gcc 4.9.0
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61339
Am I doing something wrong, or is the option actually not available anymore?
I am aware of Can GCC produce struct/class name mismatches like VS?, however the answer is 10 years old and I was hoping things had improved in the meantime.
Background: I need this in a project where we also build with clang, and where these inconsistencies are treated as error.
Looking here it seems like it was integrated in gcc 4.9.0
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61339
Actually, it doesn't. It was reported in 2014 but as OP explained in
#5th post:
I can't speak for MS, but the original warning I posted was produced
by clang. It does seem to worry about mismatched tags.
In gcc -Wmismatched-tags was introduced only in December 2019 and
became a part of GCC 10 release:
$ git describe e8f1ade269a39ea86a76a2440818e1512ed480ee
basepoints/gcc-10-5517-ge8f1ade269a
Luckily, these days we have docker and official GCC releases are
officially distributed as docker images:
$ docker search gcc
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
gcc The GNU Compiler Collection is a compiling s… 587 [OK]
(...)
so you can just do:
docker run --rm -it gcc
and either mount your source directory into the docker container or
use TRAMP integration for docker
containers or any other
preferred tool to put your code into the container and use the newest gcc inside it:
root#53d309d5d619:/# g++ --version
g++ (GCC) 10.2.0
Copyright (C) 2020 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.
root#53d309d5d619:/# g++ hello.cpp -o hello -Wmismatched-tags
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
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.
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.
Use:
yum install devtoolset-9-toolchain
scl enable devtoolset-9 bash
I've been trying to code something using the new experimental feature "modules-ts" that will be included in c++20. I've cloned the gcc branch (found here: https://gcc.gnu.org/wiki/cxx-modules), and I'm trying to follow that tutorial (on the link) using modules-ts but an g++ error is preventing me from doing that:
g++: error: unrecognized command-line option ‘-fmodules-ts’
I tried to see the version of g++, to make sure that is not reading from another previous version. And the answer is:
g++ (GCC) 10.0.0 20191029 (experimental)
Copyright (C) 2019 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.
Here is the command that I'm trying to run:
g++ -fmodules-ts hello.cppm main.cpp
Modules-ts is not merged into GCC's main branch yet. You need to download GCC's source and compile it yourself, for further instructions see GCC's installation guide. Grab the source using
svn co svn://gcc.gnu.org/svn/gcc/branches/c++-modules SomeLocalDir
instead of
svn checkout svn://gcc.gnu.org/svn/gcc/trunk SomeLocalDir
and you'll get the correct version.
EDIT:
For clarification, in this answer I assumed the OP did not compile the right GCC version because there is no svn revision number inside his gcc --version.
I have run in an issue with compiling gdb from source. I am downloading version 8.2.1 but when I try to compile it, I get the following error:
configure: error: *** A compiler with support for C++11 language features is required.
make[1]: *** [configure-gdb] Error 1
My operating system is Red Hat 7.6 (Maipo) but i have a compiled from source gcc(that i set as the default one with an alias in bashrc)
gcc --version
gcc (GCC) 8.2.0
Copyright (C) 2018 Free Software Foundation, Inc.
which gcc
alias gcc='/usr/local/gcc8.2/bin/gcc'
/usr/local/gcc8.2/bin/gcc
which g++
alias g++='/usr/local/gcc8.2/bin/g++'
/usr/local/gcc8.2/bin/g++
What i have tried/read so far
Read the gdb manual regarding the configure and instalation part, also various stackoverflow links but nobody seems to have this problem
Read the README file in the gdb folder/subfolders
Tried setting the following env options CXX_FOR_TARGET=/usr/local/gcc8.2/bin/g++ GCC_FOR_TARGET=/usr/local/gcc8.2/bin/gcc (not sure if i should replace target with my actual target architecture)
Looked in the gdb-8.2.1 folder at the file config.log and found these: ac_cv_env_GCC_FOR_TARGET_value=/usr/local/gcc8.2/bin/gcc
ac_cv_prog_CXX_FOR_TARGET=/usr/local/gcc8.2/bin/g++
ac_cv_prog_GCC_FOR_TARGET=/usr/local/gcc8.2/bin/gcc
However in the C compiler section of the same config log I have found the following:
configure:4284: checking for C compiler version
configure:4293: gcc --version >&5
gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-36)
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.
I am not sure ifi can use the devtoolset-8 gdb from RedHat because i have compiled gcc with GLIBCXX_USE_CXX11_ABI=1 and on RedHat due to a bug this is disabled by default and i am not sure if gdb will be able to manage the different binary interface.
Short version: What am I doing wrong that is making the GDB configure script not find the correct compiler and how can i fix/workaround this?
Thank you very much for your help!
A C++11-capable compiler for Red Hat Enterprise Linux 7 is provided as part of Red Hat Developer Toolset. It happens to include not just GCC 8, but GDB 8.2 as well, so you may not even have to compile it yourself. The DTS C++ compiler has been built in a special way so that it interoperates with the system C++ runtime. Unless you have replicated those modifications in your GCC build, it will not be compatible with the rest of the system (and you will have to replace the system libstdc++ library).
The system compiler in Red Hat Enterprise Linux 7 is based on GCC 4.8. In that version, C++11 support was still experimental and not enabled by default. You can try to configure GDB with
./configure CXX="g++ -std=gnu+11"
but this is not recommended (only the C++98 mode is supported).
The configure script does not use shell aliases because those are not inherited by shell scripts invoked from a shell. You will have to specify the full path to the C++ compiler explicitly (in the CXX= argument to configure), or adjust the PATH environment variable manually, or use scl enable to do so in a more polished fashion (for software collections such as Developer Toolset).
The Problem:
I'm trying to install a program called mapnik from source on CentOS 7. When I run ./configure I get the following error.
C++ compiler does not support C++11 standard (-std=c++11), which is required. Please upgrade your compiler to at least g++ 4.7 (ideally 4.8)
Unfortunately its not as simple as just updating gcc because when I run:
gcc --version
I get:
gcc (GCC) 4.8.3 20140911 (Red Hat 4.8.3-9)
Copyright (C) 2013 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.
How can I fix this? Thanks in advance.
Well, your GCC version is from 2013, so there is certainly room for update.
Furthermore(i might be mistaken here), don't you need g++ to compile C++? This would work the following way:
sudo yum install g++
The Soultion:
I ended up just removing all of Mapnik which I cloned from their git page, and instead downloaded the latest tar.gz version. From there I just installed like normal and it worked. Not the most intuitive fix, but it did the job.