Following, my previous question about How to safely deploy an application built with an upgraded compiler, there is still a doubt for me about the C++11 features compatibility. Using devtoolset-2, the application that will be built with gcc 4.8.2 but linked with libstdc++.so.6.0.13 will have full C++11 features supported or only the common set with libstdc++6.0.19 ?
I am not really sure to understand this point actually.
You shouldn't be mixing libstdc++ like that, so it's a moot point. You should redistribute the libstdc++ that comes with devtoolset-2 and link against that specifically. Otherwise the compiler and standard library will be at odds with each other, and even they won't know the answer to your question!
Then, simply look up a list of what C++11 features are supported in GCC 4.8.2.
Related
Yesterday I started making some project and today I check out that my compiler (mingw_w64) is the newest one which I find in Internet (8.1) but I don't have all functions from C++20. So maybe someone know how to figure out this? If it somehow help my IDE is QT creator.
C++ ISO standards and compilers do not progress at the same pace or with the same priorities. Also, C++ standards are available (drafts) before they are complete or officially published: quite often, compilers partially support the draft specs. The good side of this is that there are tables telling you what feature of a given standard is supported by a given version of GCC. You can find such a table for GCC here.
The current latest release of GCC is GCC 11 and C++20 support has been available since GCC 10.
Another compiler is LLVM/Clang, but I don't believe their C++20 support is on the same level as GCC yet, though I excpect it to catch up soon.
Get the latest MinGW-w64 GCC build from: http://winlibs.com/
Microsoft's (Core) Guidelines Support Library implementation is said to support GCC 5.1 - but does not specify support for other versions. Higher versions seem to be ok (anyway, 5.3.1 on my Debian Stretch) - but building the tests with GCC 4.9.3 fails.
Has anybody else implemented the GSL?
Can I use MS GSL anyway, somehow?
If not, can I use some safe subset of it? (Probably not, I know)
If not, isn't it a problem that only people with newer compilers can have a guidelines support libraries? Even though their older compilers support C++11 or even C++14?
Yes, there is one I know of: gsl-lite.
It worked fine for me so far. But I changed my compiler to a newer version and did not need it anymore.
You can also use (a rather small) subset of Microsofts implementation. If you do not need the span-classes. These are gsl_assert.h (Expects, Ensures) and gsl_utils.h (narrow, final_act, ...). I think I might have adjusted just some constexpr related things.
I am currently on RHEL 5.4 with gcc 4.1 installed, but I want to use unordered_map. As I found out, this is only introduced in C++11 to the standard, and therefore not available. One alternative would be using __gnu_cxx::hash_map, but I would prefer using standards.
On another development host I happend to have RHEL 6.4 and gcc 4.4, which knows unordered_map, but gives the following warning:
../include/c++/4.4.7/c++0x_warning.h:31:2: error: #error 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.
From the gcc homepage I can't seem to find out which gcc version supports unordered_map.
[edit]
To clarify my question:
I am stuck to several operating systems and their versions by customer requirements, therefore I cannot always update to the latest GCC version and be happy. I need to maintain compatibility of my software across all platforms.
I am therefore searching for the minimum GCC version required to use unordered_map. I am aware of the fact that supplying -std=c++0x to GCC fixes the error above, but I dont know how far the "experimental" warning means I should not be using unordered_map.
Some guys in this thread strongly advise not to use this experimental C++11 implementation
... so what should I do?
You cannot find such information on the GCC page. There is information about library features, but only about current version of GCC. In your GCC 4.4, you can simply use -std=c++0x flag to remove the warning.
If you are scared about experimental and cannot update the compiler - just don't use unordered_map from C++11. You can write your own, use one from tr1, or use the one from boost, no matter.
If you just look at GCC site - there is message there:
Important: GCC's support for C++11 is still experimental. Some
features were implemented based on early proposals, and no attempt
will be made to maintain backward compatibility when they are updated
to match the final C++11 standard.
By the way, all features of the C++11 standard are realized in GCC, it's actually old standard, since now C++14 is already approved, but support is still expiremental.
I have no idea WHY it's still experimental, for example on clang site:
Clang fully implements all published ISO C++ standards including
C++11, as well as the upcoming C++14 standard, and some parts of the
fledgling C++1z standard, and is considered a production-quality C++
compiler.
And only C++1z support is experimental.
You should upgrade to gcc 4.9.2, if you can. Otherwise use gcc 4.4. They'll both need the -std=c++0x option.
I am using GCC to compile a C++ application on Ubuntu 13. I want to be able to use C++11 features in my code, but at the same time still be able to produce a binary that my users can run on older versions of Ubuntu.
If I compile on Ubuntu 13 with the latest version of GCC my binary will not run on Ubuntu 12 since glibc is not forward compatible:
(How compatible are different versions of glibc?)
What are my options?
Is this even possible without requiring my users to jump through massive hoops?
If not, what do my users have to do to be able to run the binary (i.e. can they install the newer glibc on the older version of Ubuntu)?
Note: I don't not want to consider statically linking glibc since:
I've read that this is a very bad idea
Licensing issues
Cross-distribution compatibility issues
Currently my application does not use any C++11 features and I compile on an older version of Ubuntu with an older version of GCC to avoid this problem. But it makes me sad not being able to use the latest and greatest language features :(
You can try to use Boost Libraries which have quite the same features as C++11 and is "more retro-compatible" than C++11 : it will easily compile on older version of Ubuntu.
Otherwise the best option might be to ask to the users of Ubuntu 12.04 to upgrade there GCC from 4.6 to 4.7 or more recent :
http://www.swiftsoftwaregroup.com/upgrade-gcc-4-7-ubuntu-12-04/
You are asking "how do I use code that isn't on older systems".
The answer is of course, "Include the code with your project".
If you think through what you're asking, you'll realize that in any case, you'll need the code for the c++11 functions in libstdc++. So if they aren't on ubuntu 12, YOU have to add them. Therefore, you'd have to have it statically linked. it's the only way to ensure it will run on an arbitrary ubuntu12 system.
Well you could make a fancy installation, but in the end, it'd just be your apps "dynamically linking" to the libstdc++, so it may as well be statically linked, since no other program is going to be looking for it on ubuntu12
In general, a c++ library is compatible only if the same compiler is used and (!) the versions of the compilers are matching (you might be lucky, though). There is no way to be portable in this sense, besides writing C-code.
This question already has answers here:
How to determine the version of the C++ standard used by the compiler?
(9 answers)
Closed 6 years ago.
Recently I had faced compiling errors in a c++ code I wrote so I've been asked if I was using a C++11 compiler, but honestly I don't know how to check on my compiler version ! so any idea how to figure this out ??
Btw I'm using codeblocks as an IDE which includes the GCC compiler and GDB debugger from MinGW. also if I'm compiling my c++ code under Linux what command should I run to know my compiler version ?
That can be a tricky question. C++11 refers to a version of the
standard, not to a version of the compiler. Different compilers, and
different versions of any given compiler, will typically implement a mix
of versions of the standard, at least for recent versions. More or
less, because any implementation of C++11 will be fairly new, and thus
probably fairly buggy.
Most compilers have options to output the version; many will output it
systematically in verbose mode. For g++, try g++ --version. Recent
versions of g++ do have some support for C++11, but you have to activate
it with -std=c++0x (rather than the usual -std=c++03 or
-std=c++98). As the name (c++0x, rather than c++11) indicates, it
is not truly C++11; it is an implementation of some (most?) of the
major new features, in a preliminary version based on various working
papers, and not the final standard.
(FWIW: I don't think any compiler fully implements all of C++11, but I'd
love to be proven wrong.)
You can find out your compiler version like this:
g++ --version
That doesn't tell you if you are using c++11. To use c++11 features, you would have to call the compiler with thr -std=c++0x flag:
g++ -std=c++0x ....
Bear in mind that gcc doesn't implement 100% of c++11 yet, and how much it implements depends on the version. See here for a table of supported features.
EDIT: strictly speaking, if you are using GCC you cannot be using a fully compliant c++11 compiler due to the missing features. But versions 4.6.1 onwards cover a great deal of the standard.
If you're in linux, checking the version is easy.
> gcc --version
Will tell you the version you have. Note that GCC C++11 support is incomplete still, you can find the details here: http://gcc.gnu.org/projects/cxx0x.html
I've used a few C++11 features myself, namely initializer lists, and the nullptr constant. I'm using GCC 4.6 and it's working fine.
edit: And yes, as #jaunchopanza said, you'll need the -std=c++0x compiler flag to make it work. If you're using Code::Blocks, just right-click on your project, choose Build options..., and check the item that says Have g++ follow the coming C++0x ISO C++ language standard [-std=c++0x]