MinGW g++ 4.8.1-4 doesn't recognize -std=c++14 - c++

I installed MinGW by following their home page to their sourceforge and using mingw-get-setup.exe. This installed g++ 4.8.1-4. GCC 4.8 is supposed to support C++14 with a command-line switch, but I just get an "unrecognized option" error.
Is this a bug with MinGW? With GCC? What can I do about it? Since I know someone will ask, I want C++14 for its for-each loops. I'm using iterators for now, but for-each would improve both readability and writability.
EDIT: Found out my g++ build supports c++11, so I can use for-each. But still no luck on c++14 support.

g++ 4.8 simply does not support C++14, also MinGW is quite outdated when there are more new versions of gcc.
Alternatives you can use
If you want really to use C++11 or C++14 on windows with gcc you should be using one of the following options:
https://msys2.github.io/ (Uses MinGW-w64 internally).
http://mingw-w64.org/doku.php (it supports 32-bits too).
http://tdm-gcc.tdragon.net/.

Related

Which Version of Code::Blocks supports C++11, C++14 and C++17 Compilers?

Please give me the Version of Code::blocks, currently i'm using Code::Blocks 10.05 on Windows 7 with Server Pack 1 installed. The Code::blocks i'm using does not support either of the three Compilers that i had mentioned above, Thank You.
[I'm not going to install VS, because of data limit, i atleast need C++11, so even if you Coders can give me that version of Code::blocks it would be more than enough]
Definitely the latest version (20.03) which supports C++11, C++14, C++17 and even C++20, if the compiler allows it. If you always want a compiler updated to the latest standards (and upgradeable with a simple command from the shell), the advice is to install the compiler separately through the Msys2 toolchain.
Code::Blocks can't compile your code. You need a newer version of the compiler, such as GCC or Clang.
For more information refer to: How to Enable C++17 Support in Code Blocks.

How do I make sure I am utilizing C++14?

I am trying to compile some c++ I got from a book I am going through, when I try to compile I get this warning followed by 5 related errors.
main.cpp:16:9: warning: variable templates are a C++14 extension
[- Wc++14-extensions]
int table<RecordType>::CAPACITY;
^
I have never given a thought to updating c++ or being certain of what version I am using. I am compiling this in a mac using g++.
You may enable it with -std=c++14 flag. However, your GCC version should support it in the first place. Till GCC 4.9.3, you could use -std=c++1y whereas since GCC 5.2, it supports c++14 flag as well. For more info, refer to this.
Pass the -std=c++14 flag. There are also older versions with partial C++14 support which don't support -std=c++14 yet; for these, pass the -std=c++1y flag.
You need to tell the compiler which version of the standard to compile to.
Try g++ -std=c++14.
While -std=c++14 that others are recommending will enable C++14 feature support, it will also disable a bunch of things that are enabled by default, including support for advanced POSIX APIs.
Unless you specifically want to disable G++ extensions, you should use -std=gnu++14 not -std=c++14

Compile C++11 code on mac?

I'm new to C++11. I've tried:
clang++ -std=c++11 -stdlib=libc++ *.cc
It works, but my questions is:
Is there anyway to set these flag as default for clang++?
How to update g++ 4.2 to a version that supports C++11?
Which way do you think it's the best to compile C++11 code on mac?
Thanks.
Brett has described how to install GCC it with MacPorts. Here’s how to do it with Homebrew, which styles itself (rightfully!) as a modern replacement of MacPorts:
brew tap homebrew/versions
brew install --enable-cxx gcc48
As far as I know the easiest way to install the most recent Clang is by downloading the compiled version linked in dsign’s answer – and, as Brett mentioned, since Apple uses clang internally it’s not advised to tinker with that installation – just put yours somewhere else.
Concerning what the “best” compiler is there are two things to consider in addition to what Brett has already said:
GCC is much older and more mature than Clang. Internal compiler errors do happen occasionally in Clang. That said, it’s maturing rapidly because it’s being pushed by several companies.
Clang is feature complete for C++11, GCC 4.8 is not. One very obvious example of this is the fact that GCC 4.8 still has no working <regex> implementation, which is a shame.
Outside of an IDE (e.g., in shell), I normally have the variable CXX set to: "clang -std=c++11 -stdlib=libc++" in .profile / .tcshrc / etc., since this is picked up by most configure scripts too. On the cmd line I might use: $CXX -c foo.cc
MacPorts gcc-4.8.1 works well: "[sudo] port install gcc48 [-universal]"
"[sudo] port select --set gcc gcc48" will make this the default gcc, g++, etc.
Don't attempt to update or modify the system tools, like the old gcc-4.2 / llvm hybrid that comes with Xcode.
I don't know what you mean by 'best' way in the 3rd part of your question, but with Apple's support (they employ the primary author of LLVM), and other projects like FreeBSD behind it, clang will only continue to improve. It's already much faster than gcc, has far better error messages / diagnostics (especially for C++ and templates), and a modular architecture. For OS X, it's the clear choice.
Answers:
I don't think so
You install another g++ version alongside 4.2, it is bad karma to remove the one that comes with the system. To install a new one, check this
Same goes for clang. You can download it here.
In general, I totally recommend that you get better g++ compilers, 4.2 is quite old and its code quality is not as good. And using c++ 11 is totally worth it.
Do it all in Xcode's build settings like most Apple developers. Xcode simplifies life in many ways.

Know g++ Version of Code blocks in Windows

I am solving questions on Interviewstreet.com. They said they use C++ version g++ 4.6.3,C0x mode.
I am writing code on code blocks. So i want to know which version iam using in code blocks is it in C0x mode or C11 mode??
I have tried using g++ --version i got g++ TDM-2 mingw32 4.4.1.Can u tell me where i can get this kind of information.
what is the difference between C++ 0x and C++11??
You'll have to update the version of g++ to 4.6.3 (or later) if you want to use c++11 features. See this question and it's answers on how to do it for deb linux.
Then you'll have to pass --std=c++0x to the compiler in options. You should be able to easily find them in codeblocks.
what is the difference between C++ 0x and C++11??
c++0x is a synonym for c++11.
The command:
g++ --version
gives you the version of your g++ or mingw compiler. Since you got g++ TDM-2 mingw32 4.4.1 then your version is 4.4.1. If you want to use version 4.6.3 as in that web site, then you would have to update.
It wouldn't hurt to use a newer than 4.6.3 version of mingw, so please see here for the latest version. This page offers an windows installer for mingw.
After installation, you would have to configure CodeBlocks to use the newly installed compiler by looking into Compiler and debugger settings -> Toolchain executables tab and setting the paths for the compiler-related executables to the new ones.
Hope this helps.
EDIT:
Here is a small tutorial/example of what the CodeBlocks settings look like.

GCC std::thread not found in namespace std

I am using GCC 4.5.0 with the Eclipse IDE (if that matters) on Windows via MinGW.
I'm using the -std=c++0x flag.
I find that _GLIBCXX_HAS_GTHREADS still isn't defined, so thread for me still isn't a member of namespace std. -- or perhaps it is something else.
What does one do to get C++11 threading support with GCC?
P.S. It doesn't recognize the -pthread flag. I read in a question elsewhere on this site that this works.
Edit: Stupid me: pthread is a library, not an option. It's installed, gcc can find the header, but still no cigar.
Works fine on Linux (g++ -std=c++0x -lpthread with no additional defines).
However, this thread on Cygwin mailing list suggests that, at least as of 4.4, _GLIBCXX_HAS_GTHREADS was disabled by an autoconf test when building libstdc++ because pthread implementation of cygwin is missing pthread_mutex_timedlock. Perhaps MinGW has the same problem.
Also, this thread on comp.lang.c++.moderated says the same thing. Not supported by the library.
What does one do to get C++0x threading support with GCC?
Use Boost? Seriously http://gcc.gnu.org/onlinedocs/libstdc++/manual/status.html claims threads aren't complete even in mainline head so it isn't going to be in any current release.
The native Windows builds of gcc do not support the new C++0x/C++11 thread library.
The (commercial) Just::Thread library adds support to the TDM port of gcc 4.5.2 for Windows, as well as MSVC.
Use this builts of mingw: http://code.google.com/p/mingw-builds/downloads/list
There is already a lightweight header-only library that implements std::thread and sync primitives in pure win32 API:
https://github.com/meganz/mingw-std-threads
IT should work with any version of MinGW that has proper C++11 support.