How to compile GRASS GIS on MS Windows

This page explains how to compile portable GRASS GIS on MS Windows using these scripts.

There is a great wiki page that explains a step-by-step procedure on how to compile GRASS GIS on MS Windows, but it requires the installation of Visual Studio (optionally?) and installs compiled GRASS GIS into the OSGeo4W directory structure. Since I just wanted to compile and run it from the Git repository, I needed to slightly modify the steps in the wiki page.

See also How to cross-compile GRASS GIS for MS Windows.

1   For OSGeo4W v1

1.1   Installing OSGeo4W v1

  1. Download and run the OSGeo4W installer (64-bit or 32-bit)
  2. Advanced Install, Next
  3. Install from Internet, Next
  4. C:\OSGeo4W64 (64-bit) or C:\OSGeo4W (32-bit), Next
  5. Next
  6. Direct Connection, Next
  7. Select a download site, Next
  8. Install the following packages:
    • cairo
    • fftw
    • fftw-devel (32-bit only)
    • freetype-devel
    • freetype-devel-mingw (32-bit only)
    • gdal-ecw
    • gdal-mrsid
    • liblas-devel
    • libxdr
    • msys
    • pdcurses
    • python3-pywin32
    • python3-wx
    • regex-devel
    • wxpython
    • zstd-devel
  9. The following packages are required by GRASS GIS, but they will be automatically installed by dependency.
    • gdal
    • geos
    • iconv
    • libjpeg
    • libpng
    • libpq
    • libtiff
    • proj
    • sqlite3
    • zlib
    • zstd

Or

  1. Download the OSGeo4W installer (64-bit or 32-bit)
  2. Start the cmd window
  3. Run the following command in the cmd window:
    • For 64-bit systems,
      osgeo4w-setup-x86_64-v1.exe -A -g -k -q -s http://download.osgeo.org/x86_64 -P cairo,fftw,freetype-devel,gdal-ecw,gdal-mrsid,liblas-devel,libxdr,msys,pdcurses,python3-numpy,python3-pywin32,python3-wx,regex-devel,wxpython,zstd-devel
    • For 32-bit systems,
      osgeo4w-setup-x86-v1.exe -A -g -k -q -s http://download.osgeo.org/x86 -P cairo,fftw,fftw-devel,freetype-devel,freetype-devel-mingw,gdal-ecw,gdal-mrsid,liblas-devel,libxdr,msys,pdcurses,python3-pywin32,python3-wx,regex-devel,wxpython,zstd-devel

1.2   Installing MSYS2

  1. Download and run the MSYS2 installer (as of October 22, 2021, 64-bit or 32-bit)
  2. Next
  3. C:\msys64 (64-bit) or C:\msys32 (32-bit), Next
  4. Next
  5. Uncheck Run MSYS2 64bit now (64-bit) or Run MSYS2 32bit now (32-bit), Finish
  6. Run MSYS2 MinGW 64-bit (64-bit) or MSYS2 MinGW 32-bit (32-bit)
  7. Install the following packages (both 64-bit and 32-bit)
    pacman --noconfirm -S tar libintl make flex bison diffutils git dos2unix zip
  8. Install these packages:
    • mingw-w64-x86_64-gcc for a full GCC environment
    • mingw-w64-x86_64-pkg-config for configure -lcairo -lfreetype
    • mingw-w64-x86_64-cairo for lib/cairodriver (cairo-ps.h)
    • mingw-w64-x86_64-python3-six for scripts/d.correlate
    • For 64-bit systems,
      pacman --noconfirm -S mingw-w64-x86_64-gcc mingw-w64-x86_64-pkg-config mingw-w64-x86_64-cairo mingw-w64-x86_64-python3-six
    • For 32-bit systems,
      pacman --noconfirm -S mingw-w64-i686-gcc mingw-w64-i686-pkg-config mingw-w64-i686-cairo mingw-w64-i686-python3-six

2   For OSGeo4W v2

2.1   Installing OSGeo4W v2

Alternatively, you can install OSGeo4W v2.

  1. Download and run the OSGeo4W installer (osgeo4w-setup.exe)
  2. Advanced Install, Next
  3. Install from Internet, Next
  4. C:\OSGeo4W, Next
  5. Next
  6. Direct Connection, Next
  7. Select a download site, Next
  8. Install the following packages:
    • python3-core
    • proj-devel
    • gdal-devel
    • liblas-devel
    • netcdf-devel
    • geos-devel
    • libtiff-devel
    • libpng-devel
    • sqlite3-devel
    • cairo-devel
    • freetype-devel

Or

  1. Download the OSGeo4W installer (osgeo4w-setup.exe)
  2. Start the cmd window
  3. Run the following command in the cmd window:
    osgeo4w-setup.exe -A -g -k -q -s http://download.osgeo.org/osgeo4w/v2/x86_64/ -P python3-core,proj-devel,gdal-devel,liblas-devel,netcdf-devel,geos-devel,libtiff-devel,libpng-devel,sqlite3-devel,cairo-devel,freetype-devel

2.2   Installing MSYS2

  1. Download and run the MSYS2 installer (as of October 22, 2021, 64-bit)
  2. Next
  3. C:\msys64 (64-bit), Next
  4. Next
  5. Uncheck Run MSYS2 64bit now (64-bit), Finish
  6. Run MSYS2 MinGW 64-bit (64-bit)
  7. Install the following packages
    pacman --noconfirm -S tar libintl make flex bison diffutils git dos2unix zip
  8. Install these packages:
    • mingw-w64-x86_64-gcc for a full GCC environment
    • libbz2-devel for configure -lbz2
    • mingw-w64-x86_64-libsystre for configure -lregex
    • mingw-w64-x86_64-fftw for configure -lfftw
    • mingw-w64-x86_64-pkg-config for configure -lcairo -lfreetype
    pacman --noconfirm -S mingw-w64-x86_64-gcc libbz2-devel mingw-w64-x86_64-libsystre mingw-w64-x86_64-fftw mingw-w64-x86_64-pkg-config

3   Compiling GRASS GIS

# add two export lines to ~/.bash_profile
cat <<'EOT' >> ~/.bash_profile
export LC_ALL=C

# for OSGeo4W v1 64-bit system
export PATH="/mingw64/bin:/c/osgeo4w64/bin:$PATH"
export PROJ_LIB="/c/osgeo4w64/share/proj"

# for OSGeo4W v1 32-bit system
# export PATH="/mingw32/bin:/c/osgeo4w/bin:$PATH"
# export PROJ_LIB="/c/osgeo4w/share/proj"

# for OSGeo4W v2
export PATH="/mingw64/bin:/c/osgeo4w/bin:$PATH"
export PROJ_LIB="/c/osgeo4w/share/proj"
EOT

# source ~/.bash_profile
. ~/.bash_profile

mkdir -p ~/usr/local/src
cd ~/usr/local/src

# download the GRASS build scripts in ~/usr/local/src/grass-mingw-scripts
git clone https://github.com/HuidaeCho/grass-mingw-scripts.git

# download the GRASS source code in ~/usr/local/src/grass
git clone https://github.com/OSGeo/grass.git

cd grass

# build GRASS
../grass-mingw-scripts/myconfigure.sh
../grass-mingw-scripts/mymake.sh

# create grass.bat in bin.x86_64-w64-mingw32 (64-bit) or bin.i686-w64-mingw32 (32-bit)
../grass-mingw-scripts/mkbats.sh

Now, grass.bat is ready to run directly from the source directory:

  • For 64-bit systems, C:\msys64\home\USER\usr\local\src\grass\bin.x86_64-w64-mingw32\grass.bat
  • For 32-bit systems, C:\msys64\home\USER\usr\local\src\grass\bin.i686-w64-mingw32\grass.bat

Just run this batch file to start GRASS GIS on your machine.

4   Installing GRASS GIS on MS Windows

# package the build
../grass-mingw-scripts/package.sh

Now, move to another Windows machine and extract the following ZIP file anywhere:

  • For 64-bit systems, C:\msys64\home\USER\usr\local\src\grass\grass80-x86_64-w64-mingw32-osgeo4w64-YYYYMMDD.zip
  • For 32-bit systems, C:\msys64\home\USER\usr\local\src\grass\grass80-i686-w64-mingw32-osgeo4w64-YYYYMMDD.zip

5   Starting GRASS GIS

You can start GRASS GIS by running grass.bat:

  • For 64-bit systems, OSGeo4W64\opt\grass\grass.bat
  • For 32-bit systems, OSGeo4W\opt\grass\grass.bat

It uses cmd.exe as the default shell.

6   Changing the default shell

To change the default shell from cmd.exe to something else, define a new environment variable called GRASS_SH:

  1. Control Panel
  2. User Accounts
  3. Change my environment variables
  4. Add a new user variable GRASS_SH=powershell (your choice of a shell)
  5. Start grass.bat

If you want a bash-like shell, download busybox64.exe as C:\bin\sh.exe and set GRASS_SH=C:\bin\sh.exe.

7   Latest daily build

7.1   How to install it

  1. Extract this zip file anywhere including an external drive for portability
  2. Run OSGeo4W64\opt\grass\grass.bat

7.2   Official daily builds

Please note that this build is not an official daily build from the GRASS GIS development team. It is my personal daily build packaged as a ZIP file using compile.sh. This script compiles the latest main branch of the official GRASS GIS repository and packages everything GRASS GIS requires including OSGeo4W64 and Python 3.

References