Compiler support for upcoming C++0x
The only compiler that has an implementation of concepts is conceptgcc (and even that is incomplete - but it is good enough to get a good feel for the feature).
Visual C++ 2010 Beta has some useful C++0x support - you can play with lambdas, rvalue references, auto, decltype.
Comeau C++ or the EDG based compilers are surprisingly not as advanced I would have expected them to be in their implementation of C++0x.
GCC 4.4 (variadic templates, initializer lists, inline namespaces, autor, decltype) probably has the most features implemented out of any of the other compilers, but is lagging in concepts and lambdas (separate branch development is ongoing).
C++ compiler that supports C++0x features?
Both the 2008 Visual C++ 'Feature Pack' and g++ support some features.
The list of C++0x features supported by g++.
The Visual C++ 2008 Feature Pack ... includes an implementation of TR1. Portions of TR1 are scheduled for adoption in the upcoming C++0x standard as the first major addition to the ISO 2003 standard C++ library. Our implementation includes a number of important features such as:
- Smart pointers
- Regular expression parsing
- New containers (tuple, array, unordered set, etc)
- Sophisticated random number generators
- Polymorphic function wrappers
- Type traits
- And more!
C++0x compiler support issue
Ok so it looks like ${CMAKE_CXX_FLAGS} was including
-stdlib=libc++
According to this post When is it necessary to use use the flag -stdlib=libstdc++? it's not necessary, so removed it seemed to solve the issue
What is the difference between -std=c++0x and -std=c++11
You should prefer -std=c++11
.
(Note: I assume -std=c++11x
is a typo in your question)
The old -std=c++0x
is only needed for older compiler versions that did not support -std=c++11
and they chose that name to express the preliminary and unstable nature of features (and the ABI) of the then upcoming C++11
(and when it was still unclear whether that would eventually become C++10
or C++12
). They changes some of the details adapting to the changing working drafts of the standard at the time before the C++11 standard was officially released.
If your compiler supports -std=c++11
, there is no reason to use -std=c++0x
. Concerning compatibility: There might even be differences and incompatibilities, but these are not just bound to the use of -std=c++0x
, but to specific versions of the compiler. When the compiler supports both, they should be identical.
Enabling the -std=c++0x or -std=gnu++0x compiler options
How do you compile it? if you are using console command like gcc .\cpptesting.cpp
, you should just add an option to it:gcc -std=gnu++0x .\cpptesting.cpp
If you are compiling more complex program with make
, check a makefile.
By the way, you are using pretty old gcc version, in the more recent versions this standard is enabled by default(IIRC).
Regex in C++: Requires compiler support error
and must be enabled with the -std=c++0x or -std=gnu++0x compiler options
Add one of those options, -std=c++0x
or -std=gnu++0x
, to your compiler command:
g++ -std=c++0x ...
Note if std::regex
is not supported see boost::regex
for an alternative.
What's the point of including -std=c++0x in a G++ compile command?
By default, GCC compiles C++-code for gnu++98
, which is a fancy way of saying the C++98 standard plus lots of gnu extenstions.
You use -std=???
to say to the compiler what standard it should follow.
Don't omit -pedantic
though, or it will squint on standards-conformance.
The options you could choose:
standard with gnu extensions
c++98 gnu++98
c++03 gnu++03
c++11 (c++0x) gnu++11 (gnu++0x)
c++14 (c++1y) gnu++14 (gnu++1y)
Coming up:
c++1z gnu++1z (Planned for release sometime in 2017, might even make it.)
GCC manual: https://gcc.gnu.org/onlinedocs/gcc-4.9.2/gcc/Standards.html#Standards
Also, ask for full warnings, so add -Wall -Wextra
.
There are preprocessor-defines for making the library include additional checks:
_GLIBCXX_CONCEPT_CHECKS
to add additional compile-time-checks for some templates prerequisites. Beware that those checks don't actually always do what they should, and are thus deprecated._GLIBCXX_DEBUG
. Enable the libraries debug-mode. This has considerable runtime-overhead._GLIBCXX_DEBUG_PEDANTIC
Same as above, but checks against the standards requirements instead of only against the implementations.
Which compiler(s) have the most advanced support for the current state of C++0x?
As previously stated by Travis Gockel, GCC is the compiler with best support for C++0x.
The best source to compare the availability of C++0x features by compilers is this chart that is maintained by Scott Meyers: http://www.aristeia.com/C++0x/C++0xFeatureAvailability.htm
g++ -std=c++0x and compatibility
1. If I compile a shared library with -std=c++0x or -std=g++0x, am I guaranteed that a program that uses my library doesn't need those switches (provided I have no c++0x features in the header files)? It seems to work, but I don't want to be signing up for subtle problems down the road.
C++11 support was still experimental in GCC 4.x releases (it is no longer experimental from GCC 5 onwards). Although we tried to keep things working, the answer is no, you are not generally guaranteed that will work in all cases. There are a number of ABI changes caused by using -std=c++0x
that could cause problems for programs that mix C++03 code and C++11 code, see http://gcc.gnu.org/wiki/Cxx11AbiCompatibility for more details. If your library doesn't export any of the symbols described on that page then you should be fine.
2. The standard library for C++11 in g++ 4.4 is quite incomplete. Since much of the standard library is header-only and gnu's header files are generally full of version ifdefs, I would think that there may be a way to use a more recent version of at least the header files in libstdc++. I can't use a different .so for it, though. I'm sure I can kludge this together, but is it possible to do something like this correctly?
No, there is absolutely no chance whatsoever that will work. The headers from later versions use features not supported by 4.4, and even if you could use them you'd need to use the newer libstdc++.so
. Just no.
The headers are not full of version #ifdefs
, almost the only ones you'll find are checks for __GXX_EXPERIMENTAL_CXX0X__
which is defined by G++ when you use -std=c++0x
but that doesn't mean your 4.4 version supports lambdas, non-static data member initializers, proper rvalue reference semantics, default/deleted functions etc. that later headers make liberal use of. You must use libstdc++ headers with the same version of GCC they came with.
In short, if you want proper C++11 support you need to use a newer compiler.
If you can't use a newer compiler you can't get proper C++11 support.
Related Topics
Writing X264 from Opencv 3 with Ffmpeg on Linux
Communicate with Codesys Program on a Linux-Based Wago Pfc200 Plc
A Better Way to Split a String into an Array of Strings in C/C++ Using Whitespace as a Delimiter
Findwindow Does Not Find the a Window
What Happens to Interprocess Memory If One of The Processes Dies Unexpectedly
Round to Nearest Multiple of a Number
How to Find an Object with Specific Field Values in a Std::Set
When to Mark a Function in C++ as a Virtual
How to Set Background Color of Window After I Have Registered It
Gstreamer Recording Video with Audio
How to Sort C++ Array in Asc and Desc Mode
Extract Text from PDF Document Based on Position C++
Is Static Object Guaranteed to Be Initialized
Overloading Postfix and Prefix Operators
How to Format a Datetime to String Using Boost
Addresses of Identical Function Template Instantiations Across Compilation Units