- 1 Installing MSYS2
- 2 Building GridLAB-D from Source
- 3 Running GridLAB-D from Compiled Source Code
The MSYS2 environment is used to build GridLAB-D 4.1 or newer for the Windows OS. It can be downloaded from http://www.msys2.org. From the website download the appropriate MSYS2 installer for 32bit (i686) and 64bit (x86_64) OS’s and install MSYS2 on your machine.
Setting Up the MSYS2 Environment
To start the MSYS2 environment start msys2.exe. As can be seen MSYS2 provides a Linux-like command terminal and environment for building GNU compliant C/C++ executables for Windows OS’s. When Running the MSYS2 environment for the first time updates will need to be performed. To perform update run
$ pacman -Syuu
Type "y" and hit enter to continue. if you get a line like the following
warning: terminate MSYS2 without returning to shell and check for updates again warning: for example close your terminal window instead of calling exit
Simply close the MSYS2 window and restart the MSYS2 executable. Then to continue the updates run
$ pacman -Su
Type "y" and hit enter. You shouldn't get the warning messages from before this time.
In order to build GridLAB-D There are a couple MSYS2 packages that need to be installed. They are as follows:
- base-devel: This package provide the necessary autotools programs and libtool program needed to compile GridLAB-D
- mingw-w64-i686-toolchain (32 bit machines): This package provides gcc compiler for compiling C/C++ code.
- mingw-w64-x86_64-toolchain(64 bit machines): This package provides gcc compiler for compiling C/C++ code.
- git: This is required so the GridLAB-D github repository can be checked out.
- mingw-w64-i686-xerces-c (32 bit machines): This package provides xerces-c, a prerequisite for compiling GridLAB-D.
- mingw-w64-x86_64-xerces-c (64 bit machines): This package provides xerces-c, a prerequisite for compiling GridLAB-D.
- mingw-w64-i686-dlfcn (32 bit machines): This package provides libdl.dll and dlfcn.h, prerequisites for compiling GridLAB-D.
- mingw-w64-x86_64-dlfcn (64 bit machines): This package provides libdl.dll and dlfcn.h, prerequisites for compiling GridLAB-D.
In order to install these packages type the following:
- 32 bit machines:
$ pacman -S --needed base-devel mingw-w64-i686-toolchain git mingw-w64-i686-dlfcn mingw-w64-i686-xerces-c
- 64 bit machines:
$ pacman -S --needed base-devel mingw-w64-x86_64-toolchain git mingw-w64-x86_64-dlfcn mingw-w64-x86_64-xerces-c
Important note!!!!! After doing this /mingw64/bin or /mingw32/bin needs to be added to the path variable. In fact it would be a good idea to build a shell script so that /mingw64/bin or /mingw32/bin is added to PATH when MSYS2 is started.
Building GridLAB-D from Source
Now That MSYS2 has been set up and all needed packages have been installed the installation process for GridLAB-D can start. Start by cloning the GridLAB-D git repository from https://github.com/gridlab-d/gridlab-d. You can do this with the command:
git clone https://github.com/gridlab-d/gridlab-d.git NAMEVALUE
where NAMEVALUE is the folder in the current directory you'd like to download the code. e.g., if you are in C:\Code, this will clone GridLAB-D into C:\Code\NAMEVALUE. After the code downloads, change to that folder via:
Now checkout the correct branch, usually develop or the latest release (release/RC4.1 in this case):
git checkout release/v4.2
Installing GridLAB-D: Begin with the following.
- 32 bit machines:
./configure --prefix=<installation directory of your choice> --with-xerces=/mingw32/lib --enable-silent-rules 'CFLAGS=-g -O2 -w' 'CXXFLAGS=-g -O2 -w' 'LDFLAGS=-g -O2 -w -L/mingw32/bin' make make install
- 64 bit machines:
./configure --prefix=<installation directory of your choice> --with-xerces=/mingw64/lib --enable-silent-rules 'CFLAGS=-g -O2 -w' 'CXXFLAGS=-g -O2 -w' 'LDFLAGS=-g -O2 -w -L/mingw64/bin' make make install
Building Optional Features
There are several optional features that can be built with GridLAB-D. Those are the FNCS library, HELICS library, MySQL module, and MATLAB link.
Building with the FNCS Library
In order to build GridLAB-D with the FNCS library. FNCS must be installed on your machine. For instructions on building FNCS please see https://github.com/FNCS/fncs. Once FNCS has been installed, the path to the FNCS library and its third party libraries ZMQ and CZMQ must be added to the PATH in MSYS2. To build GridLAB-D with FNCS add the following option to the configure lines in steps 2 or 3 above:
- --with-fncs=<path to FNCS root installation directory>
For more information on the FNCS library functionality within GridLAB-D see fncs_msg.
Building with the HELICS Library
In order to build GridLAB-D with the FNCS library. HELICS must be installed on your machine. For instructions on building HELICS please see https://github.com/GMLC-TDC/HELICS-src. Once HELICS has been installed, the path to the HELICS library and its third party libraries ZMQ must be added to the PATH in MSYS2. To build GridLAB-D with HELICS add the following option to the configure lines in steps 2 or 3 above:
- --with-helics=<path to HELICS root installation directory>
For more information on the HELICS library functionality with GridLAB-D see helics_msg.
Building with the MATLAB Link
In order to build the MATLAB link inside of GridLAB-D a version of MATLAB must be installed on the system. Add the following option to the configure line in steps 2 or 3 above:
- --with-matlab=<path to MATLAB install>
It is important to note that the MATLAB installation path contain no spaces. If there are spaces in the paths you can find the short name windows uses for the directory by opening up a command window and typing dir /X one directory above the directory with the spaces. An example of what --with-matlab might look like is below.
- Install path on the windows explorer: C:\Program Files\MATLAB\R2017A
- Option set with the short names: --with-matlab=c:/PROGRA~1/MATLAB/R2017A
Attention: before running a simulation with MATLAB, the environment variable %PATH% must contain the path to the MATLAB DLLs, e.g., MATLAB_DIR\bin\win64 or MATLAB_DIR\bin\win32. For more information on the MATLAB functionality within GridLAB-D see MATLAB link.
NOTE: with MATLAB r2018a and newer, there has been a slight change to external interfaces for complex numbers. You need to tell GridLAB-D to use the older/legacy interface via the compiler definition "MATLAB_DEFAULT_RELEASE=R2017b". An example configuration command would be:
./configure --prefix=$PWD/install64 --with-xerces=/mingw64/lib --with-matlab=C:/PROGRA~1/MATLAB/R2018a --enable-silent-rules 'CFLAGS=-O2 -w -DMATLAB_DEFAULT_RELEASE=R2017b' 'CXXFLAGS=-O2 -w -DMATLAB_DEFAULT_RELEASE=R2017b' 'LDFLAGS=-O2 -w'
Building the MySQL Module
In order to build GridLAB-D with MySQL set the following option to the configure line in step 2 or 3 above:
- --with-mysql=<path to the MySQL connector folder>
It is important that no space be contained in the paths. If there are spaces in the paths you can find the short name windows uses for the directory by opening up a command window and typing dir /X one directory above the directory with the spaces. An example of what --with-mysql might look like is below.
- Install path on the windows explorer: C:\Program Files\MySQL\MySQL Connector C
- Option set with short names: --with-mysql=c:/PROGRA~1/MySQL/MYQLC~1
Attention: Before running a simulation with MySQL, %PATH% must contain the path location to the MySQL DLLs, MYSQL_DIR\lib. For more information on the MySQL modules please see the main MySQL module page.
Running GridLAB-D from Compiled Source Code
After building GridLAB-D from the source code using MSYS2, you may want to run models from the command line. For this to work, you need to set up the command window environment.
Note that in all instances below, the INSTALL item should represent the install32 or install64 directory you set up in the configure step of the GridLAB-D build. You may also have to add the path to libdl.dll and libstrdc++-6.dll - these are located in the c:\msys64\mingw64\bin and c:\msys64\mingw64\mingw folders. If they are needed on your system, append them to the PATH variable below.
The following environment variable need to be set up:
- PATH must contain REPOSITORY_DIR/INSTALL/bin
- GLPATH must contain REPOSITORY_DIR/INSTALL/lib/gridlabd and REPOSITORY_DIR/INSTALL/share/gridlabd
- CXXFLAGS must be set to include REPOSITORY_DIR/INSTALL/share/gridlabd
e.g., an example for a 64-bit install in C:\GLDCompile could be done with the following commands (note these are written like Windows/MS-DOS batch file-style commands -- for MSYS, convert the slashes to forward slashes):
REM Append path set PATH=%PATH%;C:\GLDCompile\install64\bin REM Set GLPATH set GLPATH=C:\GLDCompile\install64\lib\gridlabd;C:\GLDCompile\install64\share\gridlabd REM Set the compiler flags -- note this should be forward-slash-oriented set CXXFLAGS=-IC:/GLDCompile/install64/share/gridlabd