Revision of HOWTO Build MSYS from 2009, February 23 - 12:26

Printer-friendly version

TODO: Convert to MediaWiki syntax

!!! Minimalist GNU for Windows

!! Build MSYS

! Prerequisites:

  1. The MSYS binary release from the Current package or alternatively the Snapshot package.
  2. The msysDTK binary release from the Current package.
  3. The msysDVLPR binary release from the Snapshot package.
  4. The wincon.h file from a recent version of the w32api package.

! Installation:
The MSYS release and the msysDTK release are packaged into a Windows style installer. Execute the binaries and make sure to use the same directory for the installation of both packages. You will need to untar the msysDVLPR package in the /usr directory. Then replace the /usr/include/wincon.h file with a newer version. Here are the steps:

  1. Execute the MSYS installation package.
  2. Execute the msysDTK installation package.
  3. Then, type:

$ cd /usr
$ tar -zxvf msysDVLPR-1.0.0-alpha-1.tar.gz
$ cp /mingw/include/wincon.h /usr/include/

! Alternative Installation:
With version 1.0.11 of MSYS and greater you may now put the MinGW binaries in /usr/bin. If you do this then when you install msysDVLPR you will need to:

$ mkdir /msys
$ cd /msys
$ tar -zxvf msysDVLPR-1.0.0-alpha-1.tar.gz
$ cp /mingw/include/wincon.h /msys/include/
$ SPECFILE=/msys/bin/../lib/gcc-lib/i686-pc-msys/2.95.3-1/specs
$ mv ${SPECFILE} ${SPECFILE}.orig
$ sed 's|/usr|/msys|g' < ${SPECFILE}.orig > ${SPECFILE}

Modify your ~~/.profile similar to:

if ~[ $MSYSTEM == MINGW32 ]; then
  export PATH=".:/usr/local/bin:/bin:$PATH"
  export PATH=".:/msys/bin:/usr/local/bin:/bin:$PATH"

! Configure and make:
You must first be in the MsysBuildEnvironment; execute msysdvlpr to enter it. The MSYS build process is designed so that you cannot build in the source directory. So, you need to create a separate build directory. I use the msys/rt directory of the source as the parent for my build directory.

$ MSYS_PREFIX=/usr (or /msys, if you used the Alternative Installation)
$ cd msys/rt
$ mkdir bld
$ cd bld
$ ../src/configure --prefix=$MSYS_PREFIX (make sure you use the MsysBuildEnvironment!)
$ make

! Troubleshooting:

  • 'mingw32-gcc: command not found' or 'mingw32-g++: command not found' or : If this happens then the configure went wrong, and the files in the ./winsup/utils are trying to be built. Do the following so that configure doesn't try to use mingw32-gcc/mingw32-g++:
# make distclean
# $ cat <<_ACEOF >/bin/mingw32-gcc
#> #! /bin/sh
#> echo "command not available"

  Rerun configure and make

  The other solution is to install MinGW (which contains mingw32-gcc and mingw32-g++). It is preferable to install it in your /mingw directory. Please remember *not* to install MinGW and MSYS in the *same* directory !

  • 'configure: error: ./configure failed for cygwin': you configured in the source directory, something that you shouldn't have done. Run a 'make distclean' and read the section above about how to configure correctly.
  • make just outputs :

# make: Entering directory `/src/msys/rt/build/etc'
# make: Nothing to be done for `all'.
# make: Leaving directory `/src/msys/rt/build/etc'

  You're probably under MINGW and not MSYS. Type 'msysdvlpr' to enter MSYS. (The caption of the window should read "MSYS:some path")

  • compile error: 'implicit declaration of function `int ~GetConsoleWindow' You didn't replace your wincon.h file as mentioned above.
  • wincrypt.h, security.h, winbase.h compile errors. You probably installed a w32api and not just the wincon.h file. All your headers are thus pretty much messed up at this point. You should restart everything from a fresh install, or if you installed the headers in /usr/local, then just delete that folder (assuming you didn't install anything else).

! Debugging, Tracing, etc.
Building a debuggable MSYS dll. |

  When debugging I like to not optimize the binary output as optimization tends to change the debugging information.  So I set a variable like so: ``ccflags='-O0 -g -fnative-struct -DDEBUGGING=1 -DTRACING=1''.  This will allow the debugging data to relate directly to the line of source being executed.

  1. ccflags='-O0 -g -fnative-struct -DDEBUGGING=1 -DTRACING=1
  2. make clean
  3. make CFLAGS="$ccflags" CXXFLAGS="$ccflags"

Installing the dll full of debugging information. |

  One of the great things about MSYS is that you can have more than one version of the dll running at the same time.  For the list below let's assume you have MSYS installed in C:\msys\1.0:

  1. cd /c/msys
  2. cp -a 1.0 debug
  3. cp <top_build_dir>/i686-pc-msys/winsup/cygwin/new-msys-1.0.dll debug/bin/msys-1.0.dll
  4. copy the desktop shortcut and modify the properties to point to the debug/msys.bat

Regression testing |

  Unfortunately I haven't kept up with the dejagnu testing that was already present in Cygwin.  One of the reasons is that I'm not setup to execute dejagnu.  I do have separate regression tests I use to check the pathing code.  I need to add these to the CVS source so that others may use them.

Tracing |

  When you build MSYS a program is created in the <top_build_dir>/i686-pc-msys/winsup/utils directory named strace.exe.  Copy this program to the /bin directory, assuming you're debugging the CVS version of MSYS or a 1.0.11 or later release.  You can then use strace to see the debugging output from the program.  There is a lot of debugging information so be sure to specify an output file.  Start the debug session like so, ``strace -o /tmp/strace.out foo''.  You can use your production version of MSYS to ``tail -f /tmp/strace.out | less'' to watch the output.  You may also use sysinternals dbgview to see the debug output.

Stack walking |

  If you stack dump you will need to determine where in the code you've actually aborted.  One of the methods I use is to create an output file of using objdump with the -S and -s switches.  I then use gvim to view and find the addresses within the stack frame.

!Best of luck and happy hacking. Of importance; don't be shy about adding your tidbits of help. Others will appreciate the knowledge.

Site Status

Site maintenance performed successfully, site online Dec 13th 12:00 AM Eastern.