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

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/

Related

Build gcc on Windows with another gcc version

How to compile the newest gcc release under Windows 10? I have the latest mingw-w64available here which isn't fully c++17 compliant (I cannot use the filesystem library). A build called winlibs is also available but it is built on mingw-w64 8.0.0, so newer standards aren't fully supported. I downloaded the compressed file gcc-10.3.0.tar.gz.
What are the steps needed to do build any new (or old) gcc release on Windows natively without resorting to cygwin or msys or wsl?
Building GCC isn't trivial. It involves multiple steps, starting with having all the dependancies available.
You already had an older winlibs release, who don't you just get the latest winlibs build from http://winlibs.com/ ?
I do not understand what problem you are having with std::filesystem. Perhaps you are using a different mingw. Here is how I get mingw64
Download and install the latest g++ 64 bit compiler from
http://www.msys2.org/ Follow installation instructions on that page.
Note that you will have to stop and restart the MSYS2 command line
tool several times. To do this, close the window and then run
C:\msys64\msys2_shell. When pacman ( packet manager ) reports "there
is nothing to do" run it once more with the command pacman -S
mingw-w64-x86_64-toolchain

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 build and install GCC on Windows 7, ver. 4.8.1

I would like to upgrade my old GCC compiler to v. 4.8.1.
Currently I'm using Code::Blocks IDE (nightly build, svn 8982), and my compiler is GCC 4.4.1.
I downloaded fresh GCC from their site - gcc.gnu.org
From what I've read in documentation, they say that I should first build compiler by myself. Afterwards, they throw something like this:
% mkdir objdir
% cd objdir
% srcdir/configure [options] [target]
However, I completly have no idea what to do with these lines.
And even if I did, afterwards come maaany lines with some additional options, where I am even more lost then before.
I don't know if there is any easy way of installing it, but from what I've read here, I can download MSYS from MinGW and it will do everything(I hope?) for me. However, from what I see there, it says that MinGW comes with already built version of GCC, meaning I won't be able to use mine anyway. Am I right? If yes, what should I do to build and use GCC? If not, then will I be able to easily install GCC after downloading MSYS?
Thanks in advance.
I can download MSYS from MinGW
YOu can.
and it will do everything(I hope?) for me.
It won't. MSys provides environment for building software that requires unix-like environment. To be more precise - autotools. If you aren't familiar with *nix build process (configure script), Mingw won't really help you.
However, from what I see there, it says that MinGW comes with already built version of GCC,
Yes, version 4.7.2 at the moment.
meaning I won't be able to use mine anyway. Am I right?
No. If you don't add Mingw/MSys to your PATH, you can keep multiple different installations on the same machine. It also SHOULD be possible to use multiple different versions of gcc within the same installation of mingw, but things can get messy here. (gcc3 and gcc4 should be able to exist, not sure about 4.7.2 and 4.8.1)
If yes, what should I do to build and use GCC?
You should search for precompiled binaries provided by somebody else. Compiling gcc yourself is possible, but for you (i.e. if you aren't arleady familiar with msys) it might not be worth the effort.
Either you could try http://mingw-w64.sourceforge.net/ or mingw-nuwen. Mingw provided by nuwen is 32bit only, but is very easy to install. The problem is that standard mingw distribution includes update tool (with "mingw uppdate" and "mingw upgrade" you can upgrade installed packages to their latest version), bug "mingw-nuwen" doesn't have such tool.
Because you say
However, I completly have no idea what to do with these lines.
You should either use precompiled mingw provded by somebody else, or use another compiler. If you don't really need bleeding-edge C++11 support ON WINDOWS, use visual studio express.

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.

Where i can download gcc and glib for Cygwin?

I'm writting application for embedded system. Where i can download gcc version 3.4.3 with glib version 2.3.4 for Cygwin ?
I have download cygwin-gcc-3.3.6-glibc-2.3.2-linux.tar.bz2 but this version isn't suitable for me...
Sometimes linux distributions have a 'compat' packages which make older libraries available. Try searching cygwin for the version of libstdc++ you're looking for.