MinGW/Eclipse Installation

For current Windows build instructions see Building GridLAB-D on Windows with MSYS2. = Overview =

Installation guide for MinGW, MSYS, Eclipse, DLFCN and Xerces for Windows and Linux.

Software to be installed

 * 1) Up-to-date GridLAB-D trunk repository
 * 2) MinGW
 * 3) MSYS
 * 4) Win-Builds
 * 5) Eclipse
 * 6) DLFCN (third party software provided in the repository)
 * 7) Xerces (third party software provided in the repository)

= Windows Installation =

MinGW and MSYS
Go to MinGW Sourceforge site using http://sourceforge.net/projects/mingw/. Download and run mingw-get-setup.exe to get MinGW package installer.

Click Install



Click Continue



Click continue



After clicking Continue the MinGW installer window should popup.



Click on Basic Setup on the top left section of the window. In the right section of the window click on the msys-base package and select Mark for Installation.



Click on All Packages on the top left section of the window. In the right section of the window scroll down and click on mingw32-autotools and select Mark for Installation. This will automatically select multiple packages.



Now click on Installation and select Apply Changes.



Then Click Apply.



Once the packages have been installed click Close.



Now There should be a C:\MinGW directory. Open Explorer and navigate to C:\MinGW\msys\1.0 and run msys.bat.



A Linux terminal window should now be open. This is where GridLAB-D will be built from using autotools. Make a directory in the root called mingw. Type cd / mkdir mingw

Close the terminal.

Win-Builds
Once MinGW and MSYS have been installed, Win-Builds can be installed. Go to http://win-builds.org and download and run the package manager (win-builds-1.5.exe). You need to run this executable twice in order to get both 32bit and x64 build capability for MinGW. The 32bit architecture looks like this.



And the 64 bits architecture looks like this.



Make sure Cygwin or MSYS is selected in either case. The directory of the existing MSYS installation should be C:\MinGW\msys\1.0. Once the desired architecture is selected, click OK. This window should pop up. Click on Process and that will install all the necessary win-build packages to C:\MinGW\msys\1.0\opt\windows_32 or C:\MinGW\msys\1.0\opt\windows_64.



When it is finished processing the window will look like this. It is ok to close the window at this point.



Switch Between 32 and 64 Bit Build Architectures: Every time the msys.bat file is run the build architecture needs to be set. To select the architecture desired type the following:

Follow windows 32 build or 64 build instructions according to your systems architecture. For Windows 32 built source /opt/windows_32/bin/win-builds-switch For Windows 64 built source /opt/windows_64/bin/win-builds-switch



To avoid running the above code everytime msys.bat is run, the default build architecture can be set by adding it to the user profile demonstrated below. Follow windows 32 build or 64 build instructions according to your systems architecture.

For Windows 32 build echo 'source /opt/windows_32/bin/win-builds-switch' >> ~/.profile For windows 64 build echo 'source /opt/windows_64/bin/win-builds-switch' >> ~/.profile Now whenever msys.bat is run the window should show.



Eclipse
This instruction set will be done using 64 bit Eclipse. If you use 64 bit Eclipse you must make sure you have a 64 bit version of Java installed. If you don’t have 64 bit version of Java you can go to http://java.com/en/download/manual.jsp and under windows select Windows Offline (64-bit) and follow the installation process.

Note that these instructions, and the screenshots later, utilize the Luna version of Eclipse. It is recommended you just use the latest version of Eclipse -- you do not need to track down a version of Luna. Eclipse can be obtained from https://www.eclipse.org/downloads/eclipse-packages/. As per the previous note, be sure to download the appropriate version (64-bit or 32-bit). Notice that the download is a zip file, so there is no installation wizard. Once it’s downloaded simply extract the folder named eclipse from the zip folder to the desired location of your choosing and Eclipse is installed.

ATTENTION: Before installing dlfcn, xerces, and GridLAB-D several things need to be added to the PATH environment variable. The following paths are: C:\MinGW\msys\1.0\bin

Follow windows 32 build or 64 build instructions according to your systems architecture. For Windows 32 Bit Builds C:\MinGW\msys\1.0\opt\windows_32\bin C:\MinGW\msys\1.0\opt\windows_32\mingw\bin For Windows 64 Bit Builds C:\MinGW\bin C:\MinGW\msys\1.0\opt\windows_64\bin C:\MinGW\msys\1.0\opt\windows_64\mingw\bin These can be added to PATH in Windows 7 by navigating to Control Panel > System and Security > System, clicking on Advanced system settings, and clicking on Environment Variables. Then path can be edited from there.

DLFCN
Download and install git ( https://help.github.com/articles/set-up-git/ ). Clone or fork the development branch of the GridLAB-D source code repository located ( https://github.com/gridlab-d/gridlab-d/tree/develop ). The location of where you cloned or forked on your computer is hereby referenced as REPOSITORY_DIR. It is required that REPOSITORY_DIR contain no spaces. Run msys.bat. From here cd to REPOSITORY_DIR/third_party/dlfcn-win32-read-only. You can specify the C drive by using /c/rest-of-the-path</tt> as illustrated below.

Note: The screenshot is for an old ticket branch, ticket 863. Yours will show the repository name you gave when cloning or forking the development branch (by default it is gridlabd).



Follow windows 32 build or 64 build instructions according to your systems architecture. To install type the following:

For Windows 32 Bit Builds ./configure --prefix=/opt/windows_32/mingw --enable-shared

make

make install For Windows 64 Bit Builds ./configure --prefix=/opt/windows_64/mingw --enable-shared

make

make install

XERCES
From the linux shell cd to REPOSITORY_DIR/third_party</tt>. Unzip xerces-c-3.1.1.tar.gz</tt>. tar -xvf xerces-c-3.1.1.tar.gz Now cd</tt> to xerces-c-3.1.1</tt> and run the autotools make</tt> process as follows. Follow windows 32 build or 64 build instructions according to your systems architecture.

For windows 32 build ./configure --build=i686-w64-mingw32 --prefix=/opt/windows_32/mingw

make

make install For windows 64 build ./configure --build=x86_64-w64-mingw32 --prefix=/opt/windows_64/mingw

make

make install

GridLAB-D
This instruction set installs GridLAB-D to a folder inside REPOSITORY_DIR</tt> called install32</tt> or install64</tt> according to your system architecture. There is no need to make the directory before installing. If you wish to change where GridLAB-D gets installed simply supply a different path to --prefix</tt> at the configure step.

NOTE: If you want to build Gridlab-D with Matlab link, use the .configure command as in Linking with MATLAB subsection. If you want Gridlab-D linked with SQL use the .configure command as in Linking with MySQL subsection. Then come back to this section and follow steps "make" and "make install" as specified below after "configure" step.

The install steps are as follows.

cd REPOSITORY_DIR autoreconf -if

(32 bit) ./configure --build=i686-w64-mingw32 --prefix=$PWD/install32 --with-xerces=/opt/windows_32/mingw --enable-silent-rules 'CFLAGS=-g -O0 -w' 'CXXFLAGS=-g -O0 -w' 'LDFLAGS=-g -O0 -w'

(64 bit) ./configure --build=x86_64-w64-mingw32 --prefix=$PWD/install64 --with-xerces=/opt/windows_64/mingw --enable-silent-rules 'CFLAGS=-g -O0 -w' 'CXXFLAGS=-g -O0 -w' 'LDFLAGS=-g -O0 -w'

make

make install

Note: You need to re-install GridLAB-D for every branch you checkout and work on. MINGW, Msys, DLFCN and Xerces need to be installed only once in your system.

Tips
 * 1) You can significantly reduce how much output is generated by using the -enable-silent-rules</tt> configure options
 * 2) You can override the default GCC compiler settings by the adding the 'CFLAGS=options</tt>' and 'CXXFLAGS=options</tt>' to your configure command.
 * 3) * Use -g -O0</tt> to enable debugging.
 * 4) * Use -w</tt> to hide all warning messages. (This is not recommended because the warnings should be addressed. But GridLAB-D has so many that it can make finding the critical error messages difficult.)
 * 5) * Override the defaults using make 'CFLAGS=options ' 'CXXFLAGS=options'</tt>
 * 6) * Alternatively you can export the <tt>CFLAGS</tt> and <tt>CXXFLAGS</tt> environment variables with the options specified. Caveat: this will affect all compiles, including that of other tools.
 * 7) If typing all the options in each time is inconvenient you can add an alias for <tt>configure</tt> in your <tt>.profile</tt> file in your home directory.  For example:
 * <tt>alias configure="./configure --enable-silent-rules --build=x86_64-w64-mingw32 --prefix=/usr/local --with-xerces=/opt/windows_64/mingw 'CFLAGS=-g -O0 -w' 'CXXFLAGS=-g -O0 -w' 'LDFLAGS=-g -O0 -w'"</tt>
 * will configure for a quiet 64-bit build installed in <tt>/usr/local</tt> with Xerces and debugging enabled and no warning messages.
 * If you have enabled silent rules, you can still see the verbose out by using <tt>make V=1</tt>.

Environment Setup
NOTE: The PATH setup mentioned in the Eclipse section above may be necessary as well, particularly if items such as libdl.dll and any of the C++ DLL files are unable to be located.

First, delete the gridlabd.exe that you see REPOSITORY_DIR.

Now that you have GridLAB-D installed, the environment needs to be set up. 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.

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

Linking with MATLAB
In order to build GridLAB-D with MATLAB you must set the option <tt>--with-matlab=path-to-MATLAB-install</tt> at the <tt>./configure</tt> step of the installation. 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 <tt>dir /X</tt> one directory above the directory with the spaces. An example of what <tt>--with-matlab</tt> might look like is below. Install path on the windows explorer: C:\Program Files\MATLAB\R2012a Option set with short names: --with-matlab=/c/PROGRA~1/MATLAB/R2012a

Note: Change Matlab version from 2012a to the one that you have installed in your system.

Use these configure statement according to your windows architecture

For Windows 32 bit build

./configure --build=i686-w64-mingw32 --prefix=$PWD/install32 --with-xerces=/opt/windows_32/mingw --with-matlab=/c/PROGRA~1/MATLAB/R2012a --enable-silent-rules 'CFLAGS=-g -O0 -w' 'CXXFLAGS=-g -O0 -w' 'LDFLAGS=-g -O0 -w'

For Windows 64 bit build

./configure --build=x86_64-w64-mingw32 --prefix=$PWD/install64 --with-xerces=/opt/windows_64/mingw --with-matlab=/c/PROGRA~1/MATLAB/R2012a --enable-silent-rules 'CFLAGS=-g -O0 -w' 'CXXFLAGS=-g -O0 -w' 'LDFLAGS=-g -O0 -w'

Attention: Before running a simulation with MATLAB, Environmental variables <tt>%PATH%</tt> must contain the path to MATLAB DLLs, e.g., <tt>MATLAB_DIR\bin\win64</tt> or <tt>MATLAB_DIR\bin\win32</tt>.

For more information on linking matlab file goto Matlab link

Matlab and Mac OX X 10.11 (El Capitan)
In addition to running <tt>./configure --with-Matlab</tt>... as above, the following definition needs to be made in the Makefile; this may or may not be correctly generated by <tt>./configure</tt> MATLAB_LDFLAGS = '-L/Applications/MATLAB_R2015a.app/bin/maci64' -Wl,-rpath -Wl,/Applications/MATLAB_R2015a.app/bin/maci64

The MATLAB path specified is the location of <tt>libmx.dylib</tt> and <tt>libeng.dylib</tt> (at least in R2015a).

Linking with MySQL
In order to build GridLAB-D with MySQL you must set the option <tt>--with-mysql=path-to-the-mysql-connector-folder</tt> at the <tt>./configure</tt> step of the installation. When running a simulation with MySQL <tt>%PATH%</tt> must contain the path the MySQL DLLs, <tt>MYSQL_DIR\lib</tt>. 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 <tt>dir /X</tt> one directory above the directory with the spaces.

Install path on the windows explorer: C:\Program Files\MySQL\MySQL Connector C Option set with short names: --with-mysql=/c/PROGRA~1/MySQL/MYSQLC~1

Use these configure statement according to your windows architecture

For Windows 32 bit build

./configure --build=i686-w64-mingw32 --prefix=$PWD/install32 --with-xerces=/opt/windows_32/mingw --with-mysql=/c/PROGRA~1/MySQL/MYSQLC~1 --enable-silent-rules 'CFLAGS=-g -O0 -w' 'CXXFLAGS=-g -O0 -w' 'LDFLAGS=-g -O0 -w'

For Windows 64 bit build

./configure --build=x86_64-w64-mingw32 --prefix=$PWD/install64 --with-xerces=/opt/windows_64/mingw --with-mysql=/c/PROGRA~1/MySQL/MYSQLC~1 --enable-silent-rules 'CFLAGS=-g -O0 -w' 'CXXFLAGS=-g -O0 -w' 'LDFLAGS=-g -O0 -w'

Running GridLAB-D on Eclipse
This need to be done for every new ticket. Before opening Eclipse, the path to gridlabd.bin.exe must be added to the PATH environment variable. If you followed the instruction above then gridlabd.bin.exe is located in REPOSITORY_DIR\install_32 or install_64\bin. In the explorer navigate to where the eclipse folder was extracted. Inside the eclipse folder, double click eclipse.exe



It will ask for a path to use for projects space. Choose your desired path and click OK.



Since you are opening Eclipse for the first time the welcome view is displayed. To get to c++ view select the circled icon.



If so desired you can minimize the welcome view altogether. The picture below shows the layout of the C/C++ View.



Before loading and running GridLAB-D. It is a good Idea to check for updates. This can be done by selecting Help > Check for Updates. Once that is finished Lets go ahead an import the ticket project into Eclipse. Select File > Import and the Import window will pop up. Expand C/C++ and select Existing Code as Makefile Project and click Next.



Give the project name of your choice. In existing code location field, provide the path to the REPOSITORY_DIR (where the repository is saved in your system). Select "MinGW GCC". Finish.



You should now see a project called gridlabd in the project explorer. Expanding this will give you the ability to see all the files in REPOSITORY_DIR.

In order to run a GridLAB-D model, the run icon should be used. The run icon is circled in green in the picture below. To run the same file to debug code the debug icon should be used. The debug icon is circled in red below.



However, we need to configure the Run and Debug first. Clicking on the down arrows will give you the access to Run Configurations and Debug Configurations. Let’s set up a run configuration that will run the validation script so select Run Configurations to open the Run Configurations window.



Double click C/C++ Application to create a new Run configuration



Give the configuration a useful name. Under Main > C/C++ Application Browse for the gridlabd.bin.exe that you build. Make sure the Project is the project in your project explorer. Make sure Disable auto build is selected as well.



Under Arguments place the valide commands to run the validation script. And make sure the working directory is the REPOSITORY_DIR. Regardless, This is where gridlabd commands would be placed for running various .glms.



Finally, under Environment, Two new variables called GLPATH and CXXFLAGS need to be added. GLPATH needs to contain the following paths <GridLAB-D install path>\lib\gridlabd and <GridLAB-D install path>\share\gridlabd. CXXFLAGS needs to contain this path <GridLAB-d install path>\share\gridlabd. Once that’s done you can select Apply and Run and the validation script should start running and the Console should start displaying the output



The exact same process needs to be applied to the Debug Configurations. You can set breakpoints through the code editor window. When the Debug run begins it will ask if you want to switch to the Debug view. Click yes. The debug run always stop at the beginning of main.c. This is ok just simply tell it to continue to the next breakpoint and you are on your way to debugging code in Eclipse. Remember: Once you make edits you need to go back to msys.bat to rebuild GridLAB-D.

= Linux Installation =

The Linux OS is much simpler. Prerequisites include git, automake, and libtool. Clone or fork the develop branch of GridLAB-D. You can build Xerces from the third_party folder. No fancy prefixes are needed for installing Xerces, a simple ./configure, make, and make install is all that is needed. Eclipse needs to be extracted from a tar file instead of a zip file. And the installation for GridLAB-D remains the same as it has always been. Although, I do recommend installing to a custom prefix. The steps for running GridLAB-D from Eclipse remain the same as stated previously above.

= Helpful Tips and Troubleshooting = In the msys terminal if "cd" to "root" ie./ ">>cd /", then you are actually in "C:\MinGW\msys\1.0".

If you ">>cd /usr" you are actually in "C:\MinGW\msys\1.0". Similarly "/usr/local" is actually "C:\MinGW\msys\1.0\local".

If you ">>cd /mingw" then you are actually in "C:\MinGW" - Yes, we actually went back a couple directories from "root". Why? Look at the "fstab" file in "C:\MinGW\msys\1.0\etc". /mingw is mounted to C:\MinGW. So you could play around with the mounting in this file if you wanted.

If you want Git commands to work from the msys bash, make sure you have the following in your system PATH: C:\Users\<Your User Name>\AppData\Local\GitHub\PortableGit_63435a79518b44808827aa3194b76bea96231189\cmd.

After a make and make install, a gridlabd.exe exists in the <tt>REPOSITORY_DIR</tt> that the installer script is not removing. We are aware and working on a fix. In the meantime manually delete this file. It often will get in the way or your testing.

=See also=
 * MinGW
 * Linux/Unix