-
Notifications
You must be signed in to change notification settings - Fork 141
Windows Build Instructions VS 2013 Express
We recommend using Visual Studio Community 2017 to build SAM for Windows.
The instructions below are for building SAM with Microsoft Visual Studio 2013 Express for Windows Desktop with Update 5 (VS 2013 Express), which was required to build SAM for Windows when we originally released the open source project and before we updated it to work with Visual Studio 2017. Visual Studio 2013 Express is an older version of Microsoft's free integrated development environment (IDE).
If you have a different version of Visual Studio installed on your computer, you can install and run VS 2013 Express side-by-side with the other version.
If you do not have VS 2013 Express installed on your computer, you can download it from the list of older versions at https://www.visualstudio.com/downloads/. Scroll to the bottom of the page and follow the link to older versions. The download requires a free Microsoft account with Visual Studio Dev Essentials. This direct link worked as of July 2017.
SAM's user interface uses wxWidgets 3.1.0. You will need to download Windows source code (as either a ZIP or 7Z file) for Version 3.1.0 from https://www.wxwidgets.org/downloads/.
-
Start VS 2013 Express.
-
Open the
build/msw/wx_vc12.sln
Visual Studio Solution file in the folder where you extracted the wxWidgets 3.1.0 files. There are project files for other versions of Visual Studio, so be sure to open thevc12
file. -
Build Debug and Release configurations for both 32-bit and 64-bit platforms: In the VS 2013 Express toolbar, choose the configuration and platform, and then either press the F7 key, or choose Build Solution from the BUILD menu.
Note. If you only plan to build SAM for one platform, and do not plan to use Visual Studio for debugging, then you can just build a single version to save time, for example, the Release configuration and 64-bit platform.
If the builds succeed, you should see one or all of the following folders in the wxWidgets-3.1.0/build/msw
folder, each containing a handful of .pch
files:
vc_mswu (release win32)
vc_mswud (debug win32)
vc_x64_mswu (release x64)
vc_x64_mswud (debug x64)
SAM's repositories do or eventually will all contain dependencies on the Google Test framework Google Test, which is a C++ unit-test framework.
-
Clone Google Test:
git clone https://github.com/google/googletest.git
-
Start VS 2013 Express.
-
Open the
googletest/googletest/msvc/2010/gtest-md.sln
Visual Studio Solution file from the folder where you cloned Google Test. Accept any upgrades that Visual Studio does to the project. -
Build Debug and Release configurations for both 32-bit and 64-bit platforms: In the VS 2013 Express toolbar, choose the configuration and platform, and then either press the F7 key, or choose Build Solution from the BUILD menu.
Note. If you only plan to build SAM for one platform, and do not plan to use Visual Studio for debugging, then you can just build a single version to save time, for example, the Release configuration and 64-bit platform.
If the builds succeed, you should see one or all of the following folders in the googletest/googletest/msvc/2010/gtest-md
folder, each containing a gtest.lib
and other build outputs:
Win32-Debug
Win32-Release
x64-Debug
x64-Release
If you plan to contribute code to the repositories, use GitHub to clone the repositories to your computer. If you want to build your own versions of the software without contributing code, or just want to examine the source code, you can either clone the repositories using GitHub, or download zip files of the repositories and extract them instead.
The repositories required to build SAM are:
- https://github.com/nrel/lk
- https://github.com/nrel/wex
- https://github.com/nrel/ssc
- https://github.com/nrel/sam
For these instructions, we put those four repositories in separate folders named, lk
, wex
, ssc
, and sam
in a single parent folder called sam_dev
. The build tools use the enviroment variables we set in the next step to find these folders, so you can organize them differently if you want. Be sure that you have both read and write permissions to the folders you use.
.../SAM_dev/lk
.../SAM_dev/wex
.../SAM_dev/ssc
.../SAM_dev/sam
Environment variables store values for programs and processes on your computer. SAM's build tools use six environment variables to determine where the files it needs are stored on your computer. Before building the projects, you should set the following environment variables to point to each of the project folders you created in Step 2, 3, and 4.
Name | Value (Folder Path) |
---|---|
WXMSW3 | wxWidgets 3.1.0 |
GTEST | googletest/googletest (look for folder with LICENSE file) |
LKDIR | LK |
WEXDIR | WEX |
SSCDIR | SSC |
SAMNTDIR | SAM |
-
If Visual Studio is running, close it.
-
Use Windows to search for "Environment Variables," and open the System Properties window.
-
On the Advanced tab, click Environment Variables. The Environment Variables window shows two lists, one for user variables and one for system variables.
-
Under the user variables list, click New, and type values for the variable name and value. For example, if you put the LK repository in
F:\SAM_dev\lk
, you would set the environment variable's name to "LKDIR" and its value to "F:\SAM_dev\lk" (you do not need to type the quotes).
If you build different branches of SAM on a regular basis, you can use a batch file to set environment variable values before you build each branch. For example, you could create a text file named set_env.bat
in the F:\SAM_dev
folder that contains:
REM wxWidgets-3.1.0 installation folder
setx WXMSW3 C:\wxWidgets-3.1.0
setx GTEST C:\googletest\googletest
REM LK, WEX, SSC and SAM folders
setx LKDIR F:\SAM_dev\my_branch\lk\
setx WEXDIR F:\SAM_dev\my_branch\wex\
setx SSCDIR F:\SAM_dev\my_branch\ssc\
setx SAMNTDIR F:\SAM_dev\my_branch\sam\
Then from a Command window, navigate to the F:\SAM_dev
folder, type set_env
and press Enter to automatically create the variables and set their values.
For each of the four projects, use VS 2013 Express to open the solution file (.sln) and build Debug and Release configurations for both 32-bit and 64-bit platforms (or for a single configuration and platform to save time) as you did for wxWidgets. Build the projects in the following order:
.../SAM_dev/lk/build_vc2013/lkvc13wx3.sln
.../SAM_dev/wex/build_vc2013/wexvc13wx3.sln
.../SAM_dev/ssc/build_vc2013/ssc_vc2013.sln
.../SAM_dev/sam/build_vc2013/SAMnt_vc2013.sln
The build order is important because of dependencies between the projects, and because the SAM build process copies libcurl
library files from the WEX folder to the SAM folder.
If you make changes to a project and are rebuilding it to compile your code, you can skip the preceding project if you did not change it. For example, if you build all for projects, and then make a modification to code in SSC, you only need to build SSC and SAM to build SAM with your changes.
Note. If you get build errors about missing files, check the environment variables to makes sure they are correctly named and point to the correct folders. When building LK, WEX or SAM, errors about missing wx/<filename>.h
files may indicate that wxWidgets has not been built for the combination of configuration and platform that you are trying to build. For example, if you are building a debug/win32 version of LK and see the messages, then you will need to go back and build a debug/win32 version of wxWidgets.
-
On the File menu, click Open Project to open the
.sln
file for the LK project. -
In the toolbar at the top of the Window, choose Debug and Win32 to build the Debug configuration for the 32-bit platform. If you are building a single configuration and platform to save time, choose the Release configuation for your platform (Win32 or x64).
-
On the Build menu, click Build, or press the F7 key.
-
The console at the bottom of the window will show you the status of the build. When the build finishes, you should see a message like "Build: 2 succeeded, 0 failed, 0 skipped." You can ignore warnings. Errors will prevent the build from succeeding.
-
When the build is complete, repeat Steps 2-4 to build Debug and Release configurations for the Win32 and x64 platforms, or skip this step if you are making a single build.
-
Close the solution, and open the next one (WEX, SSC, SAM), and repeat Steps 1-5 until you have build all four projects.
After you have built the four projects, test the build by starting SAM and running a simulation.
-
In the SAM folder, go to
...\sam\deploy\win32
or...\sam\deploy\x64
, and runsam.exe
. -
After SAM starts, on SAM's Welcome page, click Start a new project.
-
Choose Photovoltaic (detailed) and Residential (distributed).
-
Click Simulate at the bottom left of the SAM window. SAM should run a simulation and display results.
-
Click Macros under the Simulate button, click one of the macro names, and click Run macro or View code. The macro should and you should see the macro code, indicating that LK built correctly.
-
On the Location and Resource page, click View data. A DView window should open indicating that the WEX project DView built correctly. (SAM also uses DView to display data on the Results page.)