Compile for c++14 on CentOS 6 - c++

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.

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 to safely deploy an application built with an upgraded compiler

I have an application that is deployed on a centos 6.7 plateform and built with the native C++ compiler of the distribution, that is gcc 4.4.7. Now for some reasons ( actually, upgrade to Qt 5.7 ), i need to use a modern compiler with C++11 features fully supported, let's say gcc 4.8.2 from devtoolset-2. Another possibility was to built a new version of gcc from the sources. According to https://gcc.gnu.org/onlinedocs/libstdc++/manual/abi.html the 4.8.3 (but 4.8.2 is not mentionned ) version of gcc is backward compatible with the libstdc++.6.0.13 ( default c++ lib in centos 6.7 ).
I have recompiled the application with this new gcc 4.8.2 version and everything seems to run fine in the dev environment. The app use the default system c++, gcc and c libs.
However, when it comes to deployment on centos 6.7 ( after a fresh install for example ) i ask myself how safe it is to do so ? Instead on relying on ABI compatibility , would it be better to provide the latest C++ and C libraries that are compatible with the version of gcc that was used to build my app ?
Nice to see someone else doing this - I recently started doing it too!
My answer is not very authoritative, but for what it's worth, I rebuild all C++ libraries that I'll be linking against, and deploy those with my application. I also redistribute libstdc++ and libgcc_s, putting them in a special place out of the way (/usr/lib/myApplicationName/...). I ensure that my application links against all of these redistributed libraries instead of whatever's native.
I had a concern that libc compatibility might be a problem, but I haven't found that I need to do anything about any C libraries, or with libc itself.
Update: Turns out I didn't even need to do this, because I'm using devtoolset; FML.

Ubuntu to RHEL C++ cross-compilation (64bits)

Not exactly sure where this question belongs, let me know if I should move it.
Here is the issue; over the past years I have a put together a relatively large personal codebase in C++11 that I'm using for work, but my workplace runs supposedly the latest version of RHEL on their cluster, which runs gcc 4.4.7, which supports C++11 only partially.
I have battled to get a decent compiler installed, but apparently there is no easy way of making this happen, so instead I am wondering whether it would be possible to cross-compile C++11 sources on my own desktop, and export the executable on the cluster at my workplace. I just don't know where to start in order to do that:
Is it possible (and how) to cross-compile C++11 sources from Ubuntu to RHEL?
Since I am at it, is it possible to rebuild gcc 4.8 or a suitable libstdc++ (or libc++) entirely from Ubuntu to an rpm package compatible with RHEL?
(Note: I would preferably use clang (3.4) to compile on my desktop, but gcc (4.8) would be fine too.)

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

Can i use the latest features of C++11 in XCode 4 or OSX Lion? [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Can I use C++11 with Xcode?
It seems like xcode 4 contains older versions of clang and gcc. Can i uppgrade gcc or clang and use them with xcode 4? I would like to use gcc >= 4.6 or the latest clang.
My main goal is to be able to have as much of the new features from C++11 available when programming C++ on mac osx lion so ditching xcode is also an option if that is needed.
What are my options to achieve this?
The version of clang in Xcode 4.1 does support some C++11 features, including variadic templates and rvalue references. Also libc++, an implementation of the C++11 standard library is included in Lion.
See my answer to Osx Lion: Xcode 4.1 how do I setup a c++0x project for details on setting this up.
Each version of Xcode 4 adds new compiler support features. Please try Xcode 4.2 when it comes out.
Macports provides GCC 4.6, but any GCC version >= 4.2.1 (ie the latest official Apple GCC) cannot create universal binaries (32 and 64-bit code in one file) directly. There may be other drawbacks, but otherwise this should work for you.
Consider using Clang++ with libc++ http://libcxx.llvm.org/
It supports Mac OS X and has about 98% C++0x features finished except atomics.
Turns out that XCode 4.2.0 (the latest version compatible with Snow Leopard) only comes with CLANG 2.0, so no C++ '11 stuff. (Even XCode 4.2.1 still uses CLANG 2.0, so it seems like you need at least XCode 4.2.3 and Lion to use any C++ '11.
I recently spent a bit of time installing Macports GCC 4.6 and modifying some Xcode compiler templates so I could select and use it from my Xcode projects. I did eventually get it working, the main drawback was that GCC 4.6 doesn't know what to do with "blocks". If you are planning on doing any COCOA, GUI stuff then this probably isn't a good option for you (as a bunch of the NS Object header files contain blocks, you get stopped pretty early).
If you are doing any other kind of project you can probably get it to work with this method.
You can even get it to create universal binaries with some creativity. I have all the gory details on how I accomplished this here:
http://thecoderslife.blogspot.com/2015/07/building-with-gcc-46-and-xcode-4.html