Installation For Use With MSYS or Cygwin


Table of Contents

1. Installation of a POSIX-like environment
1.1. Cygwin Installation
1.2. MSYS Installation
2. Win-builds Installation
3. Change toolchain on-the-fly
4. Set a default toolchain (optional)
5. Check gcc works

This tutorial will guide you through a typical installation of Win-builds with MSYS or Cygwin. Most of it has been contributed by Vincent Torri.

1. Installation of a POSIX-like environment

The sections below explain how to install Cygwin and MSYS. Only one of them is needed; in doubt, install Cygwin rather than MSYS since the latter has a few specifics which are hard to guess.

1.1. Cygwin Installation

  1. Download either setup-x86.exe or setup-x86_64.exe (setup-x86.exe will work fine on both 32b and 64b systems).
  2. Run the installer. In the examples below, Cygwin is supposed to have been installed in C:/Cygwin.
  3. When prompted for the list of packages to install, chose at least one of mingw-w64-i686-gcc-g++ or mingw-w64-x86_64-gcc-g++ which are located in the Devel category along with pkg-config from the same category. You are of course free to install more packages to satisfy the needs of your projects.
  4. Proceed until the end of the installation (downloading takes some time).

1.2. MSYS Installation

  1. Download mingw-get-setup.exe and run it.
  2. Click on Install.
  3. Click on Change to chose another installation directory, go to C:/ and make a new directory named win_builds and validate. You are free to install anywhere else but remember to keep the various paths consistent.
  4. Click on Continue.
  5. Once the progress reaches 100%, click on Next.
  6. In the new window, select All packages and then MSYS Base System.
  7. On the right of the window, right-click on msys-base and select Mark for installation.
  8. Now click on Installation in the menu bar at the top of the window and then Apply Changes.
  9. In the new window, click on Apply. Once everything is installed, use the Close button and exit the installer.
  10. Go to C:/win_builds/msys/1.0/ , right-click on msys.bat, hover over Send To and chose Desktop (create shortcut).

2. Win-builds Installation

Run either MSYS or Cygwin according to what you have installed then download yypkg-1.4.0.exe and run it from the command-line as:

  • for MSYS: ./yypkg-1.4.0.exe --deploy --host msys
  • for Cygwin: ./yypkg-1.4.0.exe --deploy --host cygwin

The package manager will prompt for the architectures to install win-builds for and will prompt for confirmation before the actual installation of each architecture that has been chosen.

3. Change toolchain on-the-fly

The win-builds-switch script takes care of everything; run it in your shell like:

# To switch to the i686 toolchain
. /opt/windows_32/bin/win-builds-switch 32
# To switch to the x86_64 toolchain
. /opt/windows_64/bin/win-builds-switch 64

4. Set a default toolchain (optional)

The easiest way to set a toolchain by default is to add its selection to the user’s profile. The command will be executed each time an interactive shell is started and will be valid for everything started from them.

echo '. /opt/windows_32/bin/win-builds-switch 32' >> ~/.profile

5. Check gcc works

First, copy and paste the following to a file name gtk_hello_world.c:

#include <gtk/gtk.h>

int main(int argc, char *argv[]) {
    GtkWidget *window;
    gtk_init (&argc, &argv);
    window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
    gtk_widget_show  (window);
    gtk_main ();
    return 0;
}

Then run the following commands in order to test each toolchain:

# First, the 32 bits toolchain
. /opt/windows_32/bin/win-builds-switch 32
i686-w64-mingw32-gcc -o gtk_hello_world.exe gtk_hello_world.c $(pkg-config --cflags --libs gtk+-2.0)

# Then, the 64 bits toolchain
. /opt/windows_64/bin/win-builds-switch 64
x86_64-w64-mingw32-gcc -o gtk_hello_world.exe gtk_hello_world.c $(pkg-config --cflags --libs gtk+-2.0)