Upgrade G++ to which minimum version for Centos 6 compatibility - c++

Our large legacy app compiles with g++ 4.4.7 within 32-bit Centos-6.
However, I'd like to use Address Sanitizer to trouble shoot a problem with glibc corruption; MALLOC_CHECK_ not working but g++ 4.4.7 doesn't support Address Sanitizer.
I installed devtoolset-2 to get g++ v4.8.2 20140120 (Red Hat 4.8.2-15) but now the program doesn't compile because exception_ptr.h Does not support exception propagation
So thinking maybe a newer version of g++ will work. I can't find any repo to install devtoolset-3 on 32-bit Centos. (Is there one?)
Otherwise, if I recompile g++ from source, which version to choose? The GCC Home Page lists all the way to v8.
Would compiling v8 break the other apps on the box (because of ABI incompatibiilty? - which I don't understand fully)? Or best to pick the highest v4.x version?

Related

where and how do i get gcc g++ 7.3.0

I would like to use SFML but at first place i need to get the same version of SFML and dev c++ compiler. It was easy to get the SFML 7.3.0 version, but i can't find the 7.3.0 version of compiler, even the MinGW installation manager doesn't have it, but i need it. I've tried searching the internet, but i found nothing that could possibly help me. The only way for me to use SFML, is using 4.9.2 version of compiler and SFML for now, but it's old and have a lot of bugs/oversights. So if u use SFML 7.3.0 or know how to get and use it, pls tell me how to.
I don't follow your statement that you need the MinGW GCC 7.3.0 compiler to build SFML 7.3.0.
When looking at SFML (https://www.sfml-dev.org/download.php) the latest version seems to be 2.5.1.
That version builds perfectly well with more recent versions of MinGW/MinGW-w64.In fact even the latest GCC 11.2.0 can build it - I used the 64-bit standalone build from https://winlibs.com/ to try this.
GCC 7.3.0 is several years old. There is usually no reason to use very old GCC versions. Instead you can tell GCC to use an older standard of the C language with the -std= flag (e.g. -std=c89).

Compile c++14-code with g++

I'm using g++ 4.8.4 on Ubuntu 14.04 LTS. When trying to compile with '-std=c++14', I get this error:
g++: error unrecognized command line option '-std=c++14'
Compiling with '-std=c++11' works fine, so I'm not sure what's going on. Does g++ really have no support for c++14 yet? Am I using a wrong command line option?
I used "sudo apt-get install g++" which should automatically retrieve the latest version, is that correct?
For gcc 4.8.4 you need to use -std=c++1y in later versions, looks like starting with 5.2 you can use -std=c++14.
If we look at the gcc online documents we can find the manuals for each version of gcc and we can see by going to Dialect options for 4.9.3 under the GCC 4.9.3 manual it says:
‘c++1y’
The next revision of the ISO C++ standard, tentatively planned for 2014. Support is highly experimental, and will almost certainly change in incompatible ways in future releases.
So up till 4.9.3 you had to use -std=c++1y while the gcc 5.2 options say:
‘c++14’
‘c++1y’
The 2014 ISO C++ standard plus amendments. The name ‘c++1y’ is deprecated.
It is not clear to me why this is listed under Options Controlling C Dialect but that is how the documents are currently organized.
The -std=c++14 flag is not supported on GCC 4.8. If you want to use C++14 features you need to compile with -std=c++1y. Using godbolt.org it appears that the earilest version to support -std=c++14 is GCC 4.9.0 or Clang 3.5.0
G++ does support C++14 both via -std=c++14 and -std=c++1y. The latter was the common name for the standard before it was known in which year it would be released. In older versions (including yours) only the latter is accepted as the release year wasn't known yet when those versions were released.
I used "sudo apt-get install g++" which should automatically retrieve the latest version, is that correct?
It installs the latest version available in the Ubuntu repositories, not the latest version that exists.
The latest GCC version is 5.2.
Follow the instructions at https://gist.github.com/application2000/73fd6f4bf1be6600a2cf9f56315a2d91 to set up the gcc version you need - gcc 5 or gcc 6 - on Ubuntu 14.04. The instructions include configuring update-alternatives to allow you to switch between versions as you need to.

Build with gcc for systems with older gcc

Hi I am trying to build an executable on Ubuntu for RedHat 6.4 - and I am struggling due to the different gcc versions.
The RedHat 6.4 machine uses gcc 4.4.7. The Ubuntu machine uses gcc 4.6.3.
Here is what I have tried:
Install g++-4.4 on the Ubuntu machine and compile with older version of gcc: failed because the code base uses features not yet available in g++-4.4
Copy the Ubuntu libc.so.6 and libstdc++.so.6 over to the RedHat machine. The program sort of gets started, then segfaults.
Link the executable on Ubuntu statically with -Wl,-Bstatic as link options. Failed on a third party library with "warning: Using 'dlopen' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking".
So I am a bit stuck now... Any advice?
Based on comments above, decided to dump RedHat (didn't have a subscription, so not easily upgradable) on the other machine and switch to Fedora, which has the latest gcc. Not a solution that scales, but what can you do.

getting c++11 - compliant compiler

This all seems like a colossal mess.
All I want is a compiler that implements C++11, so I can use <chrono>. But I'm so confused from the very beginning.
Currently, I build programs by invoking G++, but when I check the version via $ g++ -v, I get:
gcc version 4.2.1 (Based on Apple Inc. build 5658) (LLVM build
2336.11.00)
What's going on? Am I using G++? GCC? LLVM? I don't even know. Are they the same thing?
So now I'm trying to build and download GCC 4.7 via gnu.org, but I have no idea what any of the guides are talking about. I've never seen so many acronyms for things I dont know.
Why is this so complicated? What's with all those versions, with some of them only implementing some parts of C++11 and not others?
Here's the situation on OS X.
There are two C++ compilers installed by default.
[5:49pm][wlynch#watermelon ~] g++ --version
i686-apple-darwin11-llvm-g++-4.2 (GCC) 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.11.00)
[5:49pm][wlynch#watermelon ~] clang++ --version
Apple LLVM version 4.2 (clang-425.0.24) (based on LLVM 3.2svn)
g++ is running llvm-gcc, which is the gcc frontend, and then the llvm backend.
clang++ is running clang, which is the clang frontend and then the llvm backend.
If you want a C++11 compiler on OS X without installing other packages, your only option is to use the clang compiler.
The flags necessary are:
clang++ -stdlib=libc++ -std=gnu++11
To describe the two flags I'm passing:
-stdlib=libc++ uses the libc++ standard library, instead of the gnu libstdc++. On OS X, the libc++ version has c++11 support. The gnu libstdc++ one does not.
-std=gnu++11 tells the compiler to support c++11 code features, like lambdas and enum class. You can also pass -std=c++11, which is similar, but does not enable some commonly expected gnu extensions.
Update for OS X 10.9: As of OS X Mavericks, both g++ and clang++ are actually using clang. The only difference, is that g++ will imply -stdlib=libstdc++ and clang++ will imply -stdlib=libc++. So, on Mavericks, if you'd like to use C++11, you can follow the above advice, or just do:
clang++ -std=gnu++11
Update for OS X 10.10: As of OS X Yosemite, g++ is still clang in disguise. However, neither uses libstdc++ by default anymore. Both are now on libc++.
It sounds like you have Xcode 4.6 and the latest command line tools. This is from the release notes:
Important: The LLVM GCC compiler does not include the latest Objective-C and
C++11 features. Xcode 4.6 is the last major Xcode release which includes the
LLVM GCC compiler and the GDB debugger. Please migrate your projects to use the
LLVM compiler and LLDB debugger…
I think you want to use c++ instead:
$ c++ -v
Apple LLVM version 4.2 (clang-425.0.24) (based on LLVM 3.2svn)
Target: x86_64-apple-darwin12.2.0
Thread model: posix
#sharth: The situation changed on the Mac quite significantly since the release of XCode 5.0. clang/clang++ are the default C/C++ compilers. They correspond to the LLVM version 3.3 I believe, and this version of clang++ is fully C++11-compliant. Note that clang++ --version will return a version number like "5.0.x" on the Mac but that refers to the XCode version.
I have been using the Apple clang++ in a C++11 project for months now and so far I have not seen any problems. There is absolutely no reason to use any other C++ compiler on the Mac just now :-)
The situation with GCC/G++ is not so rosy. The latest version of G++ (4.8.2) does implement most of the C++11 standard, however the standard library is not compliant! For instance, std::regex is not implemented in libstdc++, but you find this out only when you run your code and the regex constructors throw std::regex_error -s. (I found this out the hard way when trying to port the aforementioned little project to Linux.) The community believes full compliance will be achieved with the 4.9 release of G++. Until then you should use the Clang compilers on Linux as well.
I have no access to the latest Intel C++ compiler suite so have no idea how compliant icpc is.

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.