MinGW/MSYS development environment
Part 1: Setting up the base system
. Index . Base system . Local packages . GTK+ . Tools .. Projects .. Home ..

The base system consist of a compiler, a shell and a collection of UNIX command line tools. The compiler and associated tools are provided by the MinGW package, the Minimalist GNU for Windows. The MSYS package is a Minimal SYStem and provides a POSIX compatible Bourne shell and a number of essential utilities.

Installing MSYS

MSYS is the base system and provides necessary command-ilnetools. We will use the MinGW-Get intaller to install MSYS but we won't be using the bundled MinGW Compiler Suite. We'll use a different compiler package instead.

Download the MingGW-Get installer:

Run the installer. In the third wizard screen, choose the pre-packaged repository catalogues. In the fifth wizard screen, you can change the installation directory. The default C:\mingw is usually approriate.

When asked what components to install, select the following:

Do not install the MinGW Compiler Suite, make sure you deselect the C Compiler.

Once the installation has finished, start the MinGW Shell. You can find it in Start -> Programs -> MSYS -> MinGW Shell. We will use the installer's command line interface to install additional packages.

I prefer rxvt as command line terminal, install the rxvt package with the following command:

mingw-get install msys-rxvt
Next, we create a new shortcut by copying the existing MinGW Shell shortcut, or by creating a new shortcut to C:\MinGW\msys\1.0\msys.bat. Right-click on the new shortcut and open its properties. Edit it so it looks like this: You can give your new shortcut any name you like, I call it MSYS Shell. Close the MinGW Shell window, and start the MSYS Shell by double-clicking on the new shortcut.

You can paste previously copied text into the RXVT terminal with the shift+insert key combination. You can copy the commands from this guide and paste them into the terminal window. If you use the mouse to select text, it will be automaticly copied as well.

Installing MinGW

MinGW is a port of the GCC compiler to the win32 platform. Instead of the official release, we install a build from the mingw-w64 project:

If you want to build 64bit binaries, you'll also need the x86_64 package:

Unzip the packages into the C:\MinGW directory, you can use the official 7-zip utility, or any archiver that understands the 7z format. You should and up with two new subdirectories: C:\MinGW\mingw32 and C:\MinGW\mingw64.

Installing additional packages

We install a number of additional msys packages through the command line installer. Run the following commands inside the MSYS shell:

mingw-get install msys-wget
mingw-get install msys-zip
mingw-get install msys-unzip
Post-installation configuration

MSYS emulates a UNIX file system hierarchy. By default, the MSYS directory C:\MinGW\msys\1.0 will be mounted as root directory / and as /usr. The MinGW installation directory C:\MinGW is mounted as /mingw. Traditional windows drives like D: and E: can be accessed as /d or /e. Use the mount command to get an overview:

$ mount
C:\Users\Ingar\AppData\Local\Temp on /tmp type user (binmode,noumount)
C:\MinGW\msys\1.0 on /usr type user (binmode,noumount)
C:\MinGW\msys\1.0 on / type user (binmode,noumount)
C:\MinGW on /mingw type user (binmode)
c: on /c type user (binmode,noumount)
d: on /d type user (binmode,noumount)
e: on /e type user (binmode,noumount)

Mount the installation directory of the custom compiler package in a convenient location:

mount 'C:\MinGW\mingw32\' /mingw32
mount 'C:\MinGW\mingw64\' /mingw64

We will add three extra directories to /etc/fstab to be mounted whenever a new shell is started: /opt, where we will install a few extra packages, /build32 where we will download the sourcode and compile packages, and /local32, where we will install our own compiled packages. These directories can be anywhere, but to keep the setup simple and consistent we will create C:\MinGW\opt, C:\MinGW\build32 and C:\MinGW\local32 and mount them as /opt, /build32 and /local32.

Additionally, we create a 64-bit variant for each of the 32-bit directories.

Create the necessary directories:

mkdir /c/mingw/opt
mkdir /c/mingw/build32 /c/mingw/local32
mkdir /c/mingw/build64 /c/mingw/local64

Mount the directories, this will automaticly add them to /etc/fstab:

mount 'C:\MinGW\opt\' /opt
mount 'C:\MinGW\local32\' /local32
mount 'C:\MinGW\build32\' /build32
mount 'C:\MinGW\local64\' /local64
mount 'C:\MinGW\build64\' /build64

Create the necessary subdirectories in /local32 and /opt:

mkdir /opt/bin /local{32,64}/{bin,etc,include,lib,share}
mkdir /local{32,64}/lib/pkgconfig

Create /local32/etc/profile.local:

cat > /local32/etc/profile.local << "EOF"
#
# /local32/etc/profile.local
#

alias dir='ls -la --color=auto'
alias ls='ls --color=auto'

PKG_CONFIG_PATH="/local32/lib/pkgconfig"
CPPFLAGS="-I/local32/include"
CFLAGS="-I/local32/include -mms-bitfields -mthreads -mtune=pentium3"
CXXFLAGS="-I/local32/include -mms-bitfields -mthreads -mtune=pentium3"
LDFLAGS="-L/local32/lib -mthreads"
export PKG_CONFIG_PATH CPPFLAGS CFLAGS CXXFLAGS LDFLAGS

PATH=".:/local32/bin:/mingw32/bin:/mingw/bin:/bin:/opt/bin"
PS1='\[\033[32m\]\u@\h \[\033[33m\w\033[0m\]$ '
export PATH PS1

# package build directory
LOCALBUILDDIR=/build32
# package installation prefix
LOCALDESTDIR=/local32
export LOCALBUILDDIR LOCALDESTDIR

EOF

Create /local64/etc/profile.local:

cat > /local64/etc/profile.local << "EOF"
#
# /local64/etc/profile.local
#

alias dir='ls -la --color=auto'
alias ls='ls --color=auto'

PKG_CONFIG_PATH="/local64/lib/pkgconfig"
CPPFLAGS="-I/local64/include"
CFLAGS="-I/local64/include -mms-bitfields -mthreads"
CXXFLAGS="-I/local64/include -mms-bitfields -mthreads"
LDFLAGS="-L/local64/lib"
export PKG_CONFIG_PATH CPPFLAGS CFLAGS CXXFLAGS LDFLAGS

PATH=".:/local64/bin:/mingw64/bin:/mingw/bin:/bin:/opt/bin"
PS1='\[\033[32m\]\u@\h \[\033[33m\w\033[0m\]$ '
export PATH PS1

# package build directory
LOCALBUILDDIR=/build64
# package installation prefix
LOCALDESTDIR=/local64
export LOCALBUILDDIR LOCALDESTDIR

EOF

Make sure it is executed on login:

cat >> /etc/profile << "EOF"
if [ -f /local32/etc/profile.local ]; then
        source /local32/etc/profile.local
fi

EOF

Apply the new settings:

source /local32/etc/profile.local

Note that the default environment is 32-bit. You can switch to 64-bit with the following command:

source /local64/etc/profile.local
Configuring vim

(Skip this section if you don't want to use the VIM editor)

Create a configuration file for VIM:

cat > ~/.vimrc << "EOF"
" Configuration file for VIM
set nocompatible
set bs=2                " allow backspacing over everything in insert mode
set ai                  " set autoindenting on
" set backup            " keep a backup file
set nobackup            " do not keep a backup file
set history=256	        " keep 256 lines of command line history
set ruler               " show the cursor position all the time
set tabstop=8           " tab at 4 characters
set shiftwidth=8        " 4 characters indentation
set nowrap              " do not wrap long lines
set visualbell          " no bell
set background=light    " msys rxvt has a light background
"set background=dark    " mingw shell uses a black background
syntax on               " syntax highlighting on

EOF

Set vim as default editor in the 32-bit environment:

cat >> /local32/etc/profile.local << "EOF"
EDITOR=vim
export EDITOR
EOF

In the 64-bit environment:

cat >> /local64/etc/profile.local << "EOF"
EDITOR=vim
export EDITOR
EOF
Installing additional packages in /opt

We install a few third-party tools in /opt to prevent them from interfering with the default packages.

Download and install the win32 subversion client using the following commands:

cd ${LOCALBUILDDIR} && \
wget -c "http://downloads.sourceforge.net/project/win32svn/1.7.4/svn-win32-1.7.4.zip" && \
unzip svn-win32-1.7.4.zip && \
cp -va svn-win32-1.7.4/* /opt && \
mkdir /opt/share/svn-win32-1.7.4 && \
mv /opt/README.txt /opt/share/svn-win32-1.7.4

Download and install the win32 cmake client using the following commands:

cd ${LOCALBUILDDIR} && \
wget -c "http://www.cmake.org/files/v2.8/cmake-2.8.8-win32-x86.zip" && \
unzip cmake-2.8.8-win32-x86.zip && \
cp -va cmake-2.8.8-win32-x86/* /opt
Building packages

The following sections of this guide describe how to build various local packages. If you do not want to build them yourself, you can download my build:

32-bit local packages with GTK
msys-2012-06-03-local32-gtk.7z
64-bit local packages with GTK
msys-2012-06-03-local64-gtk.7z

These packages should be extracted into the main installation directory C:\MinGW.

Remember you can always switch between environments by reading the apporiate profile:

For the 32-bit build environment:

source /local32/etc/profile.local

For the 64-bit build environment:

source /local64/etc/profile.local