Monday, May 11, 2015

Installing MinGW-W64 + MSYS on Win 10 x64 (or Win 8.1 or Win 7)

(This is a repost of something I did last year, I accidentally deleted it from Blogger).

Update:  I installed this on Windows 10, and updated the procedure based on experience since the original post.

I'm a Unix/Mac guy.  I use Windows for gaming but I've never really developed on it before, because why.

When I did transition to windows relatively recently for development, I used cygwin, which worked pretty well and was Unix-like enough for me to be OK with it.  However I can't make Windows apps in cygwin, and now needing to do some prototyping for cross-platform Windows tools, I need MSYS instead of Cygwin.

After a few attempts at doing this, reading various blogs that all say to do it different ways, and not really knowing which pre-compiled code I can trust versus not trust, here is a methodology I'm happy with and generally feel is relatively safe to install.

After following this procedure:

  • MinGW (64-bit) will be installed to C:\MinGW-W64
  • MSYS (32-bit) will be installed to C:\msys

    • MSYS will use your Windows Home directory as its own.

  • You'll have a "MinTTY" shortcut to start a mintty terminal running a bash shell
  • (Windows will now feel very similar to Mac/Linux)

Download/install MinGW-W64

Go to http://sourceforge.net/projects/mingw-w64/

Download the latest installer and run it.  Choose these options:

Version: (choose the highest)
Architecture: x86_64
Threads: win32
Exceptions: seh
Build revision: (choose the highest)

Install path: C:\MinGW-W64

Note here we're using win32 threads, NOT posix threads.  On Windows, win32 threads apparently run much faster than posix.  This means that when you compile things from MinGW you must ensure that you choose the win32 thread options or you'll likely have problems compiling.

NOTE: If it fails to install (sometimes it cannot download the toolchain) then that's fine, just ignore it for now and move on to below, updating the toolchain.

Download/install MSYS

Go to http://sourceforge.net/projects/mingwbuilds/files/external-binary-packages

Download the latest revision.

Unzip to C:\

This creates the location C:\msys

Create a directory for mingw

Using Windows Explorer, navigate to C:\msys and create a new folder named mingw.

The full path of the new folder you created will be C:\msys\mingw

Don't put anything in this folder.  Leave it intentionally empty.

Mount /mingw for MSYS

Edit C:\msys\etc\fstab

It should contain (at the very least) these lines:

#Win32_Path           Mount_Point
C:/MinGW-W64/mingw64  /mingw


I also recommend that you mount your Windows homedir to /home/yourname, so that your total fstab will look like this:

#Win32_Path           Mount_Point
C:/MinGW-W64/mingw64  /mingw
C:/Users              /home

Make sure there is an empty line at the end of the file.

* If you opened any msys consoles, close them now and reopen them.

Download/install YASM


Download the latest "Win64.exe" file, for example something like http://www.tortall.net/projects/yasm/releases/yasm-1.3.0-win64.exe

Move the downloaded yasm-1.3.0-win64.exe to C:\msys\bin\yasm.exe

Configure a decent Terminal

You now have a standard Windows cmd terminal (aka Shit).  To get a nice Unix-like terminal we'll install Git for Windows which has a nice MinTTY terminal that acts similar to xterm.

Continue on in HowTo: Set up Win 10 as a Unix-like Dev Workstation until you get PuTTY/Pageant set up and Git.

Once you have Git installed you will have Git Bash, which uses MinTTY, and is a pretty nice terminal that works well with msys.

What next?

Now you have a bare-bones terminal.

You need to set up your %HOMEPATH%\.bashrc and related dotfiles to really start customizing it to look and feel the way you want.

Check out my Github home dir to see an example of how I set mine up.

References

qt-project.org has nice info about MinGW and MinGW-W64, including info RE threading and exception models, pros/cons of each, etc.

EDITS

14.Aug.16 - Removed instructions for installing old school mintty; I now suggest using Git for Windows since their mintty is much newer/nicer.

27.Jul.16 - Fixed /etc/fstab mount point.  Added empty C:\msys\mingw folder so that /mingw is visible to filesystem search utilities.

06.May.16 - Updated based on new MinGW-W64 version. No longer need to manually create MSYS shortcut.

23.Jun.15 - Removed Win 8.1 specific stuff.  Updated instructions per new MinGW-W64 v5.1.0.  Confirmed that updating the toolchain is not necessary, at least for v5.1.0 and removed that part of the instructions. Moved msys to C:\msys

11.May-15 - Updated for Windows 10. Added Windows home directory mount. Moved MSYS directory inside MinGW-W64 as we no longer need easy access to it with the Windows home diretory mounted.

17.Sep.14 - Added some clarifications. Added mingw64 toolchain update.  Added references.

14 comments:

  1. i have the problem, that when i start the MinTTy terminal and try to compile a for example .c file with the gcc compiler, the terminal gives me the error "gcc: command not found". what did i wrong?

    ReplyDelete
    Replies
    1. okay i solved it, didn't set a new path to mingw bin ^^

      Delete
    2. Great! Glad you got it working. :)

      Delete
  2. yeah, Ross. I stepped on the same rake, following your steps. if I set C:\MinGW-W64 path in MinGW installer, then real path for fstab is C:/MinGW-W64/mingw64. anyhow thank you very much for this article.)

    ReplyDelete
  3. thanks for sharing, this article help me out, sharing is caring :) What Is Ransomware Cerber

    ReplyDelete
  4. I am also a Mac user and needed a C compiler to build a small DLL using pthreads. Thanks for your guide. I had huge troubles getting a working installation because there's so much outdated and misleading infos on the web about MinGW. And the worst of it all: When you visit the MinGW SF page from a Mac, you won't get the installer.exe offered but only the source code. Took me over two hours to figure that out.

    ReplyDelete
  5. Also, please update your guide with the correct path in fstab, as Andrew Kozlov already suggested.

    ReplyDelete
  6. And one more thing: It really helps to also create a "minwg" folder inside the msys folder so that, when you "ls" in the msys shell, you actually get to see the fstab-installed mingw folder contents. Took me a while to figure out why "find / -name stdio.h" didn't find anything - that's because the root dir didn't know about the fstab inserted dir until you make it visible a as an actual dir first. Unix is weird :)

    ReplyDelete
    Replies
    1. Right you are.

      I had to create C:\msys\mingw as an empty folder using Windows Explorer, and then this works:

      ross@OriginTZ10 ~
      $ find / -name stdio.h
      /mingw/lib/gcc/x86_64-w64-mingw32/5.3.0/include/ssp/stdio.h
      /mingw/x86_64-w64-mingw32/include/c++/tr1/stdio.h
      /mingw/x86_64-w64-mingw32/include/stdio.h

      Thanks for the tip!

      Delete
  7. Many thanks for your post, it really helps me since i was unclear about the good method and the good softwares to install for just retrieving basic linux commands on a classic windows shell. I don't need big frameworks like cygwin or msys2. Now when I need a real linux environment on windows i use vagrant (+ etc) ... but when i work on windows i just need wonderful simple commands like "wget" or "where python".

    Many thanks !!

    ReplyDelete
  8. using mingw if I do something like ls / the mounts don't show up in the directory listing. This is more related to using wildcard in make. As the same problem exists. If I use wildcard /* there are no files found. As well as trying things like /c/ c:/ c:\

    any help would be appreciated

    ReplyDelete
    Replies
    1. AFAIK there is no way to list mounts. I see the same behavior as you.

      `ls /` does not show either my /c/ or /d/ mounts, however I can `cd /c` and `cd /d` just fine and the files relative to those drives are readable.

      While `df` does reveal the `/c` mount, it says nothing about my `/d` mount.

      My assumption is that this is a limitation in cygdrive.

      Anyway, the mount points do work - I'm just not sure how to be able to detect them from a shell script.

      Delete