RedHat devtoolset - implications for distributing compiled code - c++

I'm running CentOS 6.4 and need a later version of the C++ compiler to build my development tools (Qt Creator in this case).
I'm unclear on the implications of using devtools and I'm hoping someone can explain.
If I compile programs using devtools, does that means the executable will run on other Centos 6.4 installations without change?
Or..do I know have to ship libraries or other files with my compiled programs?
If so...do I have to modify my C++ code to reference the later libraries? or is this something done by the person installing my compiled program

I hope this somewhat late answer can still help you. What I found is that compiling my project with devtoolset (1.1 in my case, but that should not matter too much) on RHEL 6.4 produces binaries which can almost run on a standard RedHat EL 6.4 (should be similar for Centos 6.4).
The only trouble I ran into was compiling my project with -std=c++11, which produced some problems due to incompatible symbols. The reason is that the GCC folks considered these parts of the standard library to be experimental in GCC 4.4, so they broke ABI compatibility in some places.
Turns out, there's an easy fix: Link your programs with the additional command-line-argument -static-libstdc++. That way, the binary becomes a bit larger but is runs on an unmodified RHEL 6.4 without installing additional libraries/updates for the devtoolset.
To answer your questions explicitly:
Yes, almost.
No.
Don't change the code, just add -static-libstdc++ when linking.

Related

Choosing a default gcc/g++ compiler

Im running Matlab on linux (Elementary OS)
The problem im facing is that Matlab isnt compatible with the gcc compiler higher than 4.9.
Same question as: https://www.mathworks.com/matlabcentral/answers/348906-downgrading-gcc-g-for-use-with-mex
When I use "sudo apt get install gcc" 5.4 is automatically installed. When I remove 5.4, Matlab will not recognize 4.9 which I've installed. How do I get Matlab to recognize gcc/g++ 4.9 as my compiler?
I've also followed this but it didnt resolve the problem:
https://www.mathworks.com/matlabcentral/answers/137228-setup-mex-compiler-for-r2014a-for-linux#answer_263109
Any help would be greatly appreciated.
When I remove 5.4, Matlab will not recognize 4.9 which I've installed. How do I get Matlab to recognize gcc/g++ 4.9 as my compiler?
I use Ubuntu (from which you OS is derived) and have had a similar issue. Basically, you can use update-alternative to switch between gcc versions on your choice. Here is a link that explains how to do it.
Here is the documentation on update-alternative, if you need more in-depth knowledge of its functionalities.
Note that uninstalling the default gcc for your distro (5.4 in your case) is no longer required with this solution: you can switch back to it for you development when not using Matlab. You can even install more than two versions of gcc if needed.
Hope this solves your issue.
There is no reason to downgrade GCC for MATLAB.
The reason you run into issues on Linux is because MATLAB installs its own copies of the GCC libraries. If your MEX-files expect newer libraries, they'll fail. You can delete the GCC libraries that come with MATLAB, and it will use the newer ones on your system.
The libraries are at $(MATLABROOT)/sys/os/glnx86 for 32-bit MATLAB, and $(MATLABROOT)/sys/os/glnxa64 for 64-bit MATLAB. $(MATLABROOT) is the installation root for MATLAB.
The files in question are libgcc_s.so*, libstdc++.so* and libg2c.so* (or at least they used to be called like this, I don't have a Linux MATLAB installation here to double-check).
This trick worked for MATLAB 7.0, and still worked a month ago when I suggested this to a colleague.
I do recommend that you rename or move the files, so you can replace them if things go sour.
You will need to restart MATLAB after this change, of course.

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.

Install gcc 4.9 on windows and configure it in Netbeans

Preamble
If anything I wrote is not correct, please be so kind and correct me. I am a php developer mainly - I am not into this compiling stuff. I know there are a lot of topics around the www but they seems to be either old/outdated, very complex or links to a bunch of files on sourceforge (I have no clue what files I should download and what to do with them after downloading them).
Searching a couple of days by now
I am researching for a couple of days by now and tried different compilers and settings but I don't get a standalone executable for a c++14 programme.
First compiler
The first compiler I used was cygwin. I was able to compile it with c++14 but on other computers cygwin had to be installed as well as a cygwin dll was missing. I googled and figured out that programmes compiled using Cygwin requires this dll but cannot be included to the programme itself - or did I missed something?
Current compiler
I then switched to MinGW which seems to be a better choice as it allows to compile standalone executables which is correct as I am able to do so. Well, the MinGW setup I downloaded from http://www.mingw.org/ installed among other the gcc version 4.8.1. I need 4.9.1 for c++14.
As the title says I want to configure it in Netbeans but if there is a proper tutorial for a command line compiling it's no problem either but I try to avoid using another IDE as we use it at work, too.
drangon.org
I also heard about http://www.drangon.org/mingw/ but there are tons of links linking to similiar stuff.
My goals
Get a better understanding about gcc and this compiling stuff in general.
Install gcc 4.9.1 (preferred into MinGW as it's currently installed)
Configure it in Netbeans 8.
I suggest you to try MinGW-w64. (Download.)
It's similar to MinGW, but have better multitreading support, can easily compile x64 applications, and what's more important, at this moment it uses GCC 4.9.2.
By the way, MinGW applications require some .dlls to work too. Usually you just provide these libraries with your application, but another option is to add -static flag at linking phase. Applications that are compiled with it do not require any external library files (unless you're using 3rd party libraries that don't support static linking).

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.)

Boost Binaries for MinGW

Are there precompiled Boost binaries for MinGW? I've tried compiling them on my own and I've encountered way too much difficulty, and at this point I'm pretty sure I've broken something vital to Windows and I'm going to figure out what two months down the road. So does anybody know where I can get a precompiled boost library to use? If not, I think I'll just wait until std::thread becomes available on MinGW.
Fedora Linux 16 have them, but compiled with GCC 4.6 (C++ libraries aren't compatible between major compiler versions, Fedora 13 had Boost for GCC 4.4, Fedora 15 has for GCC4.5):
DLLs for: GCC 4.6 GCC 4.5 GCC 4.4
Static for: GCC 4.6 GCC 4.5 GCC 4.4
A free (as in freedom) program — 7-zip — can open this RPM packages on Windows.
It is much easier to cross compile for Windows with MinGW32 on Fedora than to compile with MinGW+MSYS on Windows. Often it is as easy as ./configure --host=i686-pc-mingw32 && make if you have mingw32-* packages installed with distribution's package manager.
A list of available packages for Fedora is here — search for mingw32. There are compiled C and/or C++ libraries for technologies like SDL, Curl, GTK+ with Glib and Glade, Iconv, JPEG, Ogg-Vorbis, SQLite, ZIP, SSL, PCRE, Qt, Readline, Zlib and many more.
It seems a lot of folks have issues with MinGW and Windows when it comes to Boost. I found a great 'how-to' that helped me setup the Eclipse CDT with MinGW and Boost. Worked like a charm, no issues!
How to setup MinGW, Eclipse CDT and Boost
Hope that helps. It covers both Cygwin and MinGW. I used MinGW and now I am making cross platform code in Eclipse. I am also using QMake from the Qt libraries to manage my Makefiles across the multiple platforms. Talk about comfort!
Last week I had a need for the Boost libraries in MinGW. I couldn't find any binaries, but after some very painful debugging I managed to get them compiled myself. I eventually scrapped them and switched to Visual Studio, but I was able to pull the binaries out of my recycling bin for you (compiled with GCC 4.6 I believe):
http://daxnitro.com/mingw.zip
Hopefully they'll be useful to you.