Build Process in Windows Using make - USDAForestService/ForestVegetationSimulator GitHub Wiki

Build Process in WIndows Using Make with Provided Makefile

Overview

The FVS repository includes a makefile that will automatically build FVS variants. This makefile makes use of common GNU build components and can be used in numerous Unix like environments built for Windows. The following describes the process using a variant of MSYS2 built for R, and commonly referred to as 'Rtools'.

Rtools provides a single set of tools that includes everything you need to build FVS on Windows. This document describes the process of setting things up so you can use the Rtools toolkit to build FVS executables from the source files in the open-fvs repository. Furthermore this set of tools is used to develop and test the rFVS interface. For more information on the build process, including information for other compiler tools please refer to the other build process wikis or the FAQ wiki.

Getting The Necessary Tools

You will need the appropriate permissions (e.g., Administrator privileges in Windows) to install the necessary tools, so ensure you have that before proceeding.

There are several different compiler packages that can be used to build the executables. The Rtools toolkit package will be discussed here. Refer to the appropriate wiki document for discussion of the others. Download the Rtools toolkit from http://cran.r-project.org/bin/windows/Rtools/. You will want to download the latest Rtools package, or if you are an R user, get the version that corresponds to your version of R.

Once you get the installer downloaded, run it. Include all Components and any Additional Tasks (check boxes to Edit system Path and Save version info to registry). Then just click through the rest of the installation. Unfortunately, when the installation is complete you may not see a program icon like those typically added with an installation.

Once installed, open the RTools, MSYS2 prompt and verify the following packages are installed by calling the package name followed by --version (PKG_NAME --version): gfortran gcc make gdb (not required for building but needed for debugging) sqlite3 (not required for building but needed for running FVS and running automated test see Testing)

If these packages are not install in your Rtools installation, you will need to install the 64-bit versions via the Pacman Package Manager.

NOTE: starting with Rtools version 4.0 (and later, as of this writing) users will also need to manually specify the PATH location of the directory where the C-language and Fortran compilers are located. This no longer automatically happens during installation. As an example of how to do this in Windows 10:

  1. Pull up the "Environmental Variables" dialog box by simply typing 'path' in the Windows search field.
  2. Select the "Advanced" tab at the top, then click on "Environmental Variables"
  3. Find the "System Variables" window, highlight the row with the "Path" variable and click "Edit..."
  4. Click "New" in the "Edit environmental variables window" that should have popped up
  5. Add the directory string "C:\rtools40\mingw64\bin" for 64 bit versions of FVS
  6. Add the "C:\rtools40\usr\bin" directory string
  7. Click "OK"
  8. In the same "System Variables" window, confirm there is a Variable named RTOOLS40_HOME with a Value of "C:\rtools40". This ensures the "make" command (discussed below) will work.
  9. Click all "OK" buttons until you get back to the desktop.

To test for successful installation of RTools you will need to open a Command Window. For example, on Windows this is done by clicking Start > (All) Programs > Accessories > Command Prompt.

FVS requires C-language and Fortran compilers. If you have correctly installed Rtools, everything you need will be ready for you to use. To test that you have the compilers installed and universally available via PATH environmental variable, you can enter these commands from the command prompt.

At the prompt, enter the command

gcc --version

The report resulting from this command should be similar to that shown below.

gcc (Built by Jeroen for the R-project) 8.3.0
Copyright (C) 2018 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Make sure the version shown on the first line of the report is at least 8.3.0

At the prompt, enter the command

gfortran --version

The report resulting from this command should be similar to that shown below.

GNU Fortran (Built by Jeroen for the R-project) 8.3.0
Copyright (C) 2018 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Make sure the version shown on the first line of the report is at least 8.3.0

That's it. You’ve successfully installed Rtools and can now build open-fvs programs. Now that you have verified you have successfully installed RTools, the next step is to check out the source code from the Git repository located on GitHub.

Getting the Source Files

The open-fvs files are stored in a Gitrepository. You will need a Git client software to download the files. Refer to the Downloading Source Code wiki document for detailed downloading instructions.

Building the Executables and Shared Libraries

Open a Command Window or Rtools MSYS2 bash prompt. If you don't know how to do this, refer to the "Getting the Necessary Tools" section above.

Use the cd command to navigate to the trunk/bin directory inside the directory into which you checked out the open-fvs files. If you had placed the files into a directory called MyFvsFiles you would type the command as shown below. Please note that the Windows operating system requires a backslash (\) instead of a forward slash (/) to separate directory names. Use whatever is appropriate for your operating system.

On Windows:

cd \MyFvsFiles\trunk\bin

On other operating systems:

cd /MyFvsFiles/trunk/bin

If working in a Unix like Windows Environment, you will likely need to access the root C: drive:

cd /c/MyFvsFiles/trunk/bin

FVS Sqlite-Direct Programs

The FVS programs are designed to directly read input database tables of the SQlite3 type. They are built in the 64-bit architecture.

Once you have navigated to the correct directory you are ready to make an executable. The FVS variant executables are named FVS__, where the __ is the 2-letter abbreviation for the variant (e.g., ie for Inland Empire or ls for Lake States) . Executables on Windows have the filename extension .exe added to the base name. To make an executable, type the command make FVS__ (or make FVS__.exe) with __ replaced by the variant designation. For example, to build the Inland Empire variant you would use the appropriate command shown below.

On Windows:

make FVSie.exe

On other operating systems:

make FVSie

To build the Lake States variant you would use the same command with "ie" replaced with "ls", as shown below.

On Windows:

make FVSls.exe

On other operating systems:

make FVSls

The variant executable file and the shared library with the same name (e.g., FVSls.dll on Windows) are both created created in the trunk/bin directory in which you are currently working.

A sourcelist file needs to exist in the trunk/bin directory in order to build the variants in this way. For example, the file FVSls_sourceList.txt allows you to use the make command to build the variant executable FVSls (FVSls.exe on Windows). Look in the trunk/bin directory to see which variants are currently available.

To build all of the variants for which a sourcelist file exists just type make and do not specify a variant. This could take a long time to complete.

make

To remove all the programs, object files, and build directories, use the "clean" option.

make clean

If the make command does not work, you may have an issue with automatic recognition of the path to the "make" executable. That path may need to be appropriately registered (see step #10 in the above NOTE). An alternative is to supply the full path to the "make" executable in the command above.