Setting up MinGW-w64 tools on Windows without MSYS2

I was curious how to set up MinGW-w64 on Windows without MSYS2. This post details my findings.

First of all, why am I doing this? The main reason is that I’m trying to get a “clean” build of the MinGW-w64 tools and ensure that there’s no dependencies on MSYS2. This may actually already be the case, but I’m not 100% sure. Further, while MSYS2 is a nice tool, I was curious if there was a straightforward way of getting things set up without needing the extra tools MSYS2 provides.

So anyway, there are a number of ways to set up MinGW-w64. On the MinGW-w64 download page, they’ve listed 3 different providers: MSYS2, Mingw-builds, and Win-Builds.

I can’t speak for Win-Builds as I haven’t tried it. I can speak for MSYS2, but again, I’m trying to find out how to install without it. This post will cover Mingw-builds.

The first method you can use is to use the Internet installer on the SourceForge page for Mingw-builds. Now, this works fine as long as you’re not behind a proxy server. When I experimented with this at my work, I was unable to get the installer to work, regardless of how I set up my Windows proxy settings or http(s)_proxy environment variables.

However, this does work fine from home, and based upon what happened with the installer, I can basically explain how to manually set this up without the installer, for the benefit of those who cannot get the installer to work.

The manual method is to go to the project’s file listing on SourceForge, and then to navigate to the appropriate file containing the toolchain you want. Now, while download activity indicated on this page may give you a hint, you may still find yourself confused and uneasy about which files you ought to get.

In my case, I used the Internet installer to download the latest 64-bit version of the toolchain using posix threads and SEH for exception handling. (For those who don’t quite understand what this means, here’s an SO link about posix vs win32 threads, and another link regarding the different exception handling types.) What the installer actually does is:

  • Downloads an archive from Sourceforge. In this case, it can be found under “Toolchains targetting Win64” > “Personal Builds” > “mingw-builds” > “5.3.0” > “threads-posix” > “seh”. (As I indicated previously, not exactly straightforward – but not that bad once you know where to look.)
  • Extracts this archive to a directory on your computer.
  • Sets up a small batch file for launching a command prompt with the MinGW-w64 tools on the PATH.
  • Sets up an uninstaller and start menu links.

That’s more-or-less it, so you’re not really missing much with the installer.

The one important detail is: what does the batch file do? Here’s the copy on my home computer:

echo off
set PATH=E:\mingw-w64\x86_64-5.3.0-posix-seh-rt_v4-rev0\mingw64\bin;%PATH%
rem echo %PATH%
rem cd "E:\mingw-w64\x86_64-5.3.0-posix-seh-rt_v4-rev0\mingw64\bin"
cd "C:\"
"C:\windows\system32\cmd.exe"

This is really trivial. It could even be improved slightly:

  1. Move the script directly into the mingw64 folder.
  2. Change the script to the following:
    ECHO OFF
    SET "PATH=%~dp0\bin;%PATH%"
    CD %USERPROFILE%
    START "MinGW Command Shell"
    

This is simpler and doesn’t depend on where you install MinGW-w64. It also gives you a little heads-up that the shell is MinGW-enabled as opposed to a regular command shell.

…Of course, you can go even simpler if you want: simply add the bin directory to your PATH. Totally acceptable. I happen to prefer this being more self-contained, plus I tend to do things this way with other programming language environments as well – but most users probably are fine with just tweaking the PATH and getting on with life. 🙂

Anyway, let me bring this rambling post to a close, and give some info in summary.

If you want to install the same MinGW-w64 zips as what the installer would provide but prefer (or need) to do it by hand,

  1. Go to the SourceForge page.
  2. Click on either “Toolchains targetting Win64” or “Toolchains targetting Win32” depending on whether you want an x64 or x86 toolchain.
  3. Click on “Personal Builds”.
  4. Click on “mingw-builds”.
  5. Click on the link for the version of the toolchain you want. (The version number appears to match the version of GCC provided in the toolchain.)
  6. Click on “threads-posix” or “threads-win32”. (My recommendation is “threads-posix”, and it does seem to be the most popular.)
  7. Click on the appropriate type of exception handling. Both builds offer “sjlj”, although this seems the least popular. 32-bit offers “dwarf”, and 64-bit offers “seh”. Based on what I read (but no real experience), I suggest “seh” for 64-bit (the more popular option) and “sjlj” for 32-bit (despite it being the less popular option).
  8. Download the single 7z file listed.
  9. Extract the 7z file somewhere on your system. You may need to install 7-Zip if you don’t already have it; it’s free and easily found on the web.
  10. Either:
    • Add the contained “bin” directory to your PATH environment variable.
    • Or, create a batch file as described above, place a shortcut to it somewhere convenient, and use it for launching command shells with MinGW-w64 enabled.

Anyway – I’ve probably rambled way too long on this post, but hope this helps someone out.

1 thought on “Setting up MinGW-w64 tools on Windows without MSYS2

Leave a Reply to Arghya Nandi Cancel reply

Your email address will not be published. Required fields are marked *