Install MSYS and MinGW

Post date: Oct 07, 2010 12:52:10 AM

You need a compiler to compile C and C++ software. The standard on Windows is Microsoft's Visual Studio. The free version is a very nice IDE. For compiling and running Unix applications, there is Cygwin, but then you can't run the programs outside of Cygwin.

MinGW includes the C++ compiler gcc, and utilities and libraries needed to create native Windows applications. These depend on MSVCRT (Microsoft Visual C RunTime), which is built in to Windows.

MSYS provides a Bourne shell command line interpreter, which is more familiar to Unix users than the Windows command prompt, as well as standard Unix command line programs. These are Windows versions of the command line utilities, only the shell is changed by MSYS. You can install Python, Tcl/Tk, Git, etc independently from MSYS, and they will be available in MSYS. MSYS copies Windows environment variables (including PATH), and you may change or add environment variables in the ".profile" file of your home directory.

Installation

Follow the instructions on the offical site. Here are the steps I used:

  • Download "mingw-get-setup.exe". It's an executable file that downloads and installs MSYS and MinGW.

  • Open the download folder, right-click the executable, and "Run as Administrator".

  • Follow the setup procedure. I used these options:

    • Click "Install"

    • Install to: "C:\dev\MinGW"

    • Other defaults:

      • Install support for the GUI

      • for all users

      • in the start menu

      • on the desktop

    • Select components:

      • mingw32-base

      • mingw32-gcc-g++

      • msys-base

      • msys-openssh

      • msys-vim

    • Select "Installation" menu, "Apply"

      • Click "Apply"

    • "MinGW Installation Manager" will load the catalogs, download the packages from sourceforge, then install them. This takes several minutes.

    • Click "Close".

    • Select "Installation" menu, "Quit"

Configuration

Shockingly, Windows does not have a "HOME" environment variable. This variable is used by MSYS on startup as the home directory. Use these steps to set it:

  • Go to "Start" > "Control Panel" > "System" > "Advanced system settings".

  • Click "Environment Variables..." button

  • Under "User variables", click "New..."

  • Enter variable name "HOME", variable value "C:\dev\Your_id"

Start

Open a File Explorer, and navigate to "C:\dev\MinGW\msys\1.0".

Run "msys.bat".

For a nicer console than "cmd.exe": Install mintty for MSYS

Commands

You may now start using the shell. Here are some commands to get around the system:

Notice that MSYS uses /c instead of C:\. /mingw is the MinGW installation directory, which will be used a lot when referencing system libraries, headers, and things like that. When you have code that you'd like to compile, you'll put it in a subdirectory of HOME.

Environment

Let's create a .profile and add MinGW to our path: vim .profile

#MinGW .profile

#Add developments binaries to PATH

PATH=$PATH:/c/dev/Python27/Scripts:/c/dev/git/bin

export PATH

#Aliases

alias vi='"$PROGRAMFILES/Windows NT/accessories/wordpad.exe"'

This adds my Python and Git installations to the binary search PATH. Paths may be different on your system.

The alias "vi" will call up wordpad if you accidentally type "vi" instead of "vim". Notice that the alias has single-quotes (') surrounding double-quotes ("). You can run "notepad" as a command in MSYS, since /c/Windows/System32 is already in the default path.

Notepad++ is (in my opinion) a much better editor than wordpad. If you've installed Notepad++, you could use this alias:

alias vi='"$PROGRAMW6432/Notepad++/Notepad++.exe"'

If you have Notepad++.exe open before you run the alias, "vi" will open the file and return to the shell.

What Now?

That's it for installation, next you'll be wanting to create projects, makefiles, and build things.