How to get compiler C++11

Hi all! Till now I work with compiler g++. I am a Linux user. Yesterday I found a file dealing with hash, in your tutorial. It doesn't work. I tried with g++ and then with gcc.On head of your code, it is specified that C11 is needed. How can I know if C11 is included in my g++ compiler, or gcc compiler. If not included what shall I do in order to have a compiler including C11 ??
Use the compiler flag -std=c++11 to enable C++11.
How can I know if C11 is included in my g++ compiler, or gcc compiler.

try compiling this short program:
1
2
3
4
5
6
7
8
9
10
#include <iostream>

constexpr auto SIZE = 5;
int main()
{
}

/*Error message: 
error: 'constexpr' does not name a type
note: C++11 'constexpr' only available with -std=c++11 or -std=gnu++11*/

If not included what shall I do in order to have a compiler including C11 ??

compiler only:https://nuwen.net/mingw.html
compiler with IDE: http://www.codeblocks.org/downloads

edit: some other C++11 'tests':http://blog.smartbear.com/c-plus-plus/the-biggest-changes-in-c11-and-why-you-should-care/
Last edited on
If you do have g++, then you probably have its manual page installed too and can do:
man g++

Scroll/search down to the part that explains the values that you can give with the -std option.
With my vim I tried: :!g++ -std=c++11 es.cpp -o es and now it works. Many thanks. Some hours before I tried : man g++ , more than 10000 lines and I understood nothing.
> I tried : man g++ , more than 10000 lines and I understood nothing.

Yeah, man g++ is pretty silly unless you know what you are looking for; you just get a massive wall of poorly formatted text with no cross-reference or navigation.

Try this instead: https://gcc.gnu.org/onlinedocs/gcc-6.3.0/gcc/
If you want it locally, download the tarball: https://gcc.gnu.org/onlinedocs/gcc-6.3.0/gcc-html.tar.gz
Could I mention the idea of using the latest compiler and the latest standard?

On Linux, It is fairly easy to update one's compiler to the latest version. The current standard is C++14, but C++17 is due very soon, and both gcc and clang already have support for quite a bit of it. Even though you may not be using any C++17 features, it is still a good idea to use it as the compiler may makes use of the extra features internally. One could at least use the C++14 standard, there are some simple but very useful things in that standard - like auto for example .

In terms of which compiler to use, there is a bit of an arms race between gcc and clang as to who is in front with implementation of the latest standard. It is useful to have and compile with both.

By the way, always use a high level of warnings:

g++ -std=c++17 -Wall -Wextra -pedantic-errors es.cpp -o es

JLBorges taught me that, a long time ago now :+D

Some other warnings that are very handy:
http://www.cplusplus.com/forum/general/183731/#msg899203
JLBorges wrote:
Yeah, man g++ is pretty silly unless you know what you are looking for; you just get a massive wall of poorly formatted text with no cross-reference or navigation.

Try this instead

1. The man-pages do have quite systematic format. There might be info-pages too (which are multipage with some links:
info g++


2. One should not run man or info from vim, but from bash.

3. We know exactly what to look for.
* In man type '/'. (That is equivalent of Ctrl-f of some other programs.)
* Type -std= (and Return) The hits are highlighted and focus is on the first of them.
* Type 'n' to jump to next hit (just like you might use 'F3' is some other programs.

4. There is a problem with online docs. They are for some version. The installed GCC might be different. The local man-page describes the options of the installed version. That was the question.

5. One can check the version of g++ with:
g++ --version

However, some distros backport features and thus the version-number is not always the whole truth.

6. The man and info do have documentation too:
man man
man info
info man
info info


TheIdeasMan wrote:
On Linux, It is fairly easy to update one's compiler to the latest version.

Basically true, but depends on distro. Most distro's have package management, (which one should use). That is likely to offer a specific version of GCC, if other packages depend on it. An update may thus be trivial/automatic or non-trivial.
Basically true, but depends on distro. Most distro's have package management, (which one should use). That is likely to offer a specific version of GCC, if other packages depend on it. An update may thus be trivial/automatic or non-trivial.

I had to build G++ last month (I wanted GCC 7; it's not released yet.)

If you need to do this (you maybe will if you want preemptive C++17 support), make sure you either read the documentation and configure it appropriately, or be prepared to wait many hours for the package to bootstrap itself.

The build process is relatively straightforward otherwise. It should work out of the box on most systems.
Last edited on
I have Fedora 25, where gcc is part of the distribution, so it is updated via the daily update system when a new version becomes available. But yeah, having to configure the build could be a bit involved . There are some pre-built binary packages available.

keskiverto wrote:
4. There is a problem with online docs. They are for some version. The installed GCC might be different. The local man-page describes the options of the installed version. That was the question.


The online docs JLBorges quoted, have separate pages for each & every version.

On the other side, I have found clang/llvm to be equally tricky to install / update. I had trouble trying to set a repository for clang, in order to use dnf package manager for the upgrade. So I finish up having to build that manually as well. Maybe there is another way?
Fedora 25 seems to have clang-3.8.1 in base repos:
http://www.spinics.net/lists/fedora-package-announce/msg205796.html
Were you after an upstream version?
DNF repository priorities?


@OP: "Linux user" is ambiguous; there are quite different distros and setups and devil lurks in the details. The more you tell about your system, the better (specialized) advice (the ones familiar with that system's quirks) can give.
@keskiverto

Yeah, I have 3.8.1 at the moment, but the latest version is 3.9.1

Not sure where to find a repository for that version of the dnf package. Hence needing to build it. I suppose that is not too bad, but am after the lazy option :+D

Did find this 3.9.0 for fedora26 though:

http://rpmfind.net/linux/rpm2html/search.php?query=clang

Would that work on fedora 25?
Would that work on fedora 25?

Directly? Highly unlikely.
One could download the source rpm and use 'rpmbuild --rebuild' on it.
That, if successful, creates binary rpm(s) that has been built in your system.
Thanks keskiverto

Regards :+)
So I finished up following the procedure on the llvm webpage, and now have clang v5.0.0. The fc26 rpms had dependencies which were also fc26, so it was easier to do the procedure.

http://clang.llvm.org/get_started.html
Topic archived. No new replies allowed.