TapInstalling MinGW

One thing I have noticed about much free and OpenSource software is that often the instructions for complete Noobs are very poor. Many lack

  • Any good advertising of where the packages can be found.
  • Any good description of why you might want them (see Firefox extensions for some good examples)
  • Any “Getting Started” instructions on what to download and how to install it.
  • Any place to get help.

Of course, not all fail in all of the ways, MinGW is better than some.

What is MinGW

MinGW stands for Minimal GNU for Windows and is a project to enable the extensive GNU software library to be run and utilised from a Windows environment. For many people, myself included, this means access to the excellent compilers and accessories. This enables you to compile and distribute your own and OpenSource software without requiring that the end user load a new runtime environment, libraries or DLLs unlike some similar systems like Cygwin. In particular, I use it to build a Win32 version of HTML-Tidy.

This is complemented by MSYS (which stands for Minimal System) which is a subset (fork) of Cygwin and creates a Unix-like Bourne shell environment but it is important to note that neither depends on the other and can be used independently. You can use MinGW from Windows Command Prompt if you like (though there are no GUIs).

How do you install it

This was something I struggled with even though I had done it before; a long time ago. Some of the instructions don’t appear until after it is installed. I am going to describe installing both MSYS and MinGW because it is easier to install the latter using MSYS, but you don’t need to use it again if you don’t want to. On the download page you need to skip past the Candidate section to the Current section. There you will find lots of packages.

Installing MSYS

First you will need the exe bin for MSYS (currently MSYS-1.0.10.exe). This installs very easily as it is a proper Windows Installer. Run it under a Windows Admin account and take all the defaults so that it loads into C:\msys. You get a lot of information pages with pauses; you can make notes but I will cover most of them below. The only thing I have seen which it gets wrong is that it puts the desktop shortcut into the current user rather than “All Users” so you may need to move it.

Preparing for MinGW

Create a new folder C:\mingw ready to accept the files.
The next stage is a bit tricky if you are not familiar with Unix and the “vi” editor so you may need to follow the instructions letter by letter. What we are doing here is connecting the MinGW install folder to the MSYS system. We also connect up a “home directory” in your Windows “My Documents” folder for convenience. Note that the “/”‘s go the other way to what you are used to in Windows and you don’t need to type the “$ ” which is the prompt on many lines.

Open up MSYS either from the desktop icon or from “Start | All Programs | MinGW | MSYS | msys”. This will give you a command-like window but white with coloured bits rather than black.
$ cd /etc
$ vi fstab

Now you need to type the single letter i (for insert) followed by
c:/mingw /mingw
c:/DOCUME~1/Rick/MYDOCU~1/mingw /home/Rick

No newline on the very end but exit from insert using the “Esc” key (top left of the keyboard).
Of course, instead of Rick, substitute the name of your normal day-to-day Windows login account. If it is a long name or in Windows fancy format with spaces etc. then you will need to use the DIR/X command in a Windows CMD shell to find out what its short name is.
Now type ZZ (note they are capitals) which is a shorthand save and exit command and you should now be back to the “$” prompt. Type exit to go out of MSYS. Now when you restart it you should be able to cd /mingw and be in the folder you created at the start of this section.

Installing MinGW

You will now need to download the MinGW packages you need from the web site. In the same “Current” section, I would suggest that you start with “mingw-runtime” (currently version 3.9), “mingw-utils” (currently 0.3) and “binutils” (version 2.15.91). The packages you are looking for are marked “bin” and all end in “tar.gz”. If you are going for the compiler you will also need “gcc-core” (version 3.4.2) from the gcc section, the Windows API “w32api” (version 3.6) and the make command “minggw32-make” (version 3.80.0-3). Curiously the latter is an exe at the moment. Put all these files in c:\mingw. Now if you go to your MSYS window and type
$ cd /mingw
$ ls

you should see the same files.

Now we can start installing them. This is the bit which is most useful to do from MSYS. First a little hint. Copy and paste in MSYS and most Unix-like systems works differently to Windows. Any text selected is immediately copied to the clipboard, you don’t need to type CTRL-C. To paste it to where the cursor is, click the middle mouse button. No middle button? Try clicking the wheel, it usually functions as a button as well. No wheel? Perhaps time for a small monetary investment.

Most of the files you have downloaded are compressed tar files. Compressed you will understand and it needs the “gunzip” program to uncompress them. This is provided in MSYS so, doing the first package, you need to type
$ gunzip mingw-runtime-3.9.tar
Note that it doesn’t have the “.gz” on the end (though it could) and the easiest way to do this is to select the text from the ls you did earlier and paste it onto the command line after typing “gunzip “.
Tar stands for tape archive and is a very old unix file format used for aggregating files for shipping. The tar program is provided in MSYS and one command which can be used to extract the files is
$ tar -xfpvB mingw-runtime-3.9.tar
Note the capital “B” and the file name is identical to the above and is probably still on your clipboard for paste. The files are extracted into multiple directories which you can see with an ls command or Windows Explorer. If you have finished with it you can delete the tar file or archive it somewhere; it is not needed in this directory any more.
You need to do this for each of the packages except “mingw32-make”.

Installing “make”

For some reason, “make” is installed using a Windows installer so you just need to run the exe. You just need to answer the questions and accept the default install folder C:\mingw. Now it needs a little configuration in MSYS.
$ cd /bin
$ mv make.exe mingw32-make.exe
$ cd /mingw/bin
$ mv mingw32-make.exe make.exe

This is to effectively comment out the low function MSYS “make” command and enable the fully functional GNU one.

Finishing up

You can now log out of the Windows Admin account and into your normal day-to-day account. Create a folder “mingw” in “My Documents” and then you can start up MSYS. Type ls and you should be able to see any files in your new personal “mingw” directory and you are ready to go and start using it.

If you are going to use the MinGW stuff from the Windows Command Prompt (CMD) then you need to put C:\mingw\bin into the search path so the programs can be found.
To do this right click on “My Computer” and select properties (or select “System” from the Control Panel). Select the Advanced tab and on there the “Environment Variables” button at the bottom. If there is a PATH variable in the top section then select it and click Edit, if not then click New and create one called PATH. Don’t touch the System variables in the bottom section, that is dangerous. Add the string ;C:\mingw\bin to the value (note the semi-colon which is needed to separate values but not if it is the only one). Click OK three times to get out.
Now you need to logout and log back in again and it will be all ready to go.

Running gcc from MSYS

This couldn’t be easier.
$ cd
$ gcc -o program program.c

and you are there.

Running gcc from Windows Command Prompt

Just as easy; open a CMD window by opening “Start | Run…”, enter cmd into the box and click OK. This will give the familiar black window that used to be called DOS.
cd My Documents\mingw
gcc -o program program.c

and there you are again!

Comments are closed.

^ Top