How to install C++11 C++0x header files on Redhat Enterprise - c++

I moved my application to another Linux box, after compilation, it returns an error saying
#include <atomic>
can not be resolved.
I guess the new GNU C++11 header files / libraries are not installed on new machine.
My question is how can I install them?
I am running on Redhat Enterprise, so yum install ?
Thanks.

The Red Hat Developer Toolset provides C++11 support.
(Indeed, I suspect this is the primary reason for its existence.)

The include under the version of gcc that comes with RHEL 6 is:
#include <cstdatomic>
See Runtime Library (libstdc++) section of gcc 4.4 releaste notes.
EDIT: This answer is not fully correct, because cstdatomic is the C11 file and not the C++11 one. For full C++ support in RHEL 6, the devtoolset should be used.

Looks like you'll need to install an up to date version of GCC yourself; RHEL (at least as of 6.x) does not have a version of GCC supporting C++0x in it's repositories. You can build recent versions of GCC by following GCC's installation instructions, which are distribution-neutral.
You may also be able to use a package from a more recent Fedora release, which generally contains more "bleeding edge" software than that available in RHEL.

Related

Compile for c++14 on CentOS 6

I have a C++ program that uses various C++14 features, and have been asked to compile it for a CentOS 6 system. GCC doesn't support C++14 features on CentOS 6 as far as I can tell (and based on compiler errors).
Is it possible to compile for C++14 on CentOS 6?
Assuming someone has created a whole compatibility layer for compiling C++14 on CentOS6, could I even distribute that executable? Or would the target machine ALSO have to install a compatibility layer?
I recall reading (years ago) about how to use different development toolchains at once, including I think those later than what was supported by the repos for the OS. Just can't recall details.
No, it is not possible to compile C++14 on CentOS 6. Only some C++11 features are available on CentOS 6.
CentOS runs GCC 4.4.7 where-in C++14 features start to become available with GCC 4.9 and higher.
The Boost libraries may be used to replicate some modern C++ features if on an outdated GCC version.

Will installing GCC 7.1 include std::is_base_of_v in the standard library?

I've got the GCC 5 package installed on an Ubuntu 16 machine, and I'd like to compile some code that uses the newer std::is_base_of_v and other similar "using" aliases called for in the standard library by the C++17 standard. GCC is big and I've never installed a compiler before, so I'd like to know before I begin if the standard library will be upgraded too. I'd also like to make sure that clang compilation works. Any advice is appreciated.
Here's the GCC standard library status page:
https://gcc.gnu.org/onlinedocs/libstdc++/manual/status.html#status.iso.201z
The symbol you are looking for was introduced by P0006R0. The status page above shows, it is implemented in GCC 7. You'll need that version.

MinGW: How to upgrade GCC/G++ to version 5 on Windows?

I have MinGW installed on my computer and I just found out that my GCC/G++ has problems compiling newer C++ standards. So I want to upgrade from 4.8.1-4 to the latest version (5.3 at the time of writing this).
The MinGW Installation Manager doesn't install a newer version than 4.8.1-4, so I'll probably have to do it somewhat manually. But how? I heard that Cygwin might be able to do it, but I think MinGW and Cygwin would interfere with each other (environment variables). So I'd rather not do it that way.
MSYS2 might be a good answer to your needs. It has cygwin-like environment together with mingw3/mingw64 environment. And GCC version is 5.3
Link: https://msys2.github.io/

How to update to C++11?

I am new to programming, so have never experienced a language update. With the release of C++11, I want to make use of all the new features such as lambda expressions and threads. I know I can do this with external libraries but using native language features would be more convenient.
I am using gcc 4.2.1 on Mac OS X Snowleopard in Xcode 3.2.6
What all do I need to do and update to start using C++11 features?
You can update to Xcode 4.1 (or whatever the most recent version you can get for Snow Leopard is) and get a new compiler with a few more C++11 features. There are some posts here on Stack Overflow about getting better support for C++11 in Xcode 4.1 on Snow Leopard.
But even the latest compiler available through Xcode does not support some C++11 features like lambdas. To get the best C++11 support you'll want to install a newer compiler, gcc 4.6 or 4.7, or Clang.
I frequently build the latest version of clang from source. It's not difficult to do if you're familiar with building other open source software. I use the git repos for clang and llvm, http://llvm.org/git/llvm.git and http://llvm.org/git/clang.git. You can also find instructions on their website for getting started: http://clang.llvm.org/get_started.html. Once you have the source for clang and llvm it's just ./configure && make && sudo make install. (you might want to run the tests before installing, since this is directly out of the repository. After make do make check in the llvm directory, and once that passes cd down to tools/clang and run make test. If everything is okay then sudo make install)
I don't remember if Snow Leopard included libc++ or not, so you may need to get that as well. http://libcxx.llvm.org/
Once everything is built and installed you can do:
clang++ -std=c++11 -stdlib=libc++ main.cpp && ./a.out
and you should have just about the best C++11 support around.
Recent patches in clang have really improved support for the last features you're likely to notice as a new C++ programmer. There are still a few bits and pieces left, but as of 3.1, and as far as I'm aware, clang has every C++11 feature that either gcc 4.7 or VC++11 has and more besides. libc++ also has the fewest gaps in terms of C++11 standard library features IME (though I think VC++'s standard library will also be pretty complete once they catch up on language features, e.g. char32_t and char16_t as native types so that the standard's mandated specializations for those types can be used).
Basically you only need to get a toolchain that has support for the new features. In macosx that would be either GCC or clang++. You might need to download/compile a particular version if needed (i.e. if the feature that you want to try is not in a prepacked compiler bundle but is available in the repository).
I downloaded and compiled the latest trunk of clang++ from subversion to do some testing, and installed g++ 4.6 with macports in Snow Leopard. I remember that I had some issues with the setup of the environment, but don't quite remember which of the compilers gave me problems or how I solved them. Google is your friend there :)
If you have homebrew installed, from this article, just two steps:
brew tap homebrew/dupes
brew install gcc --enable-cxx --enable-fortran --use-llvm

upgrading boost version

I'm using RHEL 5.3, shipped with gcc 4.1.2 and boost 1.33.
So, there's no boost::unorded_map, no make_shared() factory function to create boost::shared_ptr and other features available in newer releases of boost.
Is there're a newer version of boost compatible with the version of gcc?
If yes, how the upgrade is performed?
Download the latest version (1.43.0) of the Boost libraries from the Boost website and follow the steps in the getting started guide, which explains how to build Boost on a number of platforms, including Linux.
Simply download and install the newest version; it will adapt itself automatically to your compiler.
Sure, just download the latest source from link text. If you are only using header only libraries, it just needs to be unpacked. If you are using one of a handful that require a library, you will need to build those.