Skip to content

Build Linux

Bill Hamilton edited this page Aug 6, 2021 · 5 revisions

Platform requirements

The open source and NREL release-build platform is CentOS 7 and has been built on Ubuntu 16.04, Fedora 25 and Mint 18.2. The minimum gcc version supported is 4.8.5 and the minimum libc support is 2.17. The gcc and libc versions can be found by:

gcc --version   
ldd --version

Before you begin, you will need to install git and g++ if they are not already installed. For example:

sudo apt-get install git
sudo apt-get install g++

To install CMake, download a Linux distribution from https://cmake.org/download/. For step-by-step instructions, see for example https://www.linuxfordevices.com/tutorials/install-cmake-on-linux.

1. Clone the SolarPILOT and SSC code repositories

  1. The source code for the LK, WEX, SSC, SolTrace, and SolarPILOT projects should go in a single parent directory. The git clone command automatically creates a directory for the repository, so you do not need to create a directory before you clone it. You may first need to install git with sudo apt install git. All repositories can be cloned from the NREL GitHub channel except SSC, which should be cloned from @mjwagner2 and checked out to solarpilot-develop.

    cd spt_dev
    for repo in lk wex SolTrace SolarPILOT ; do git clone https://github.com/nrel/$repo ; done
    git clone https://github.com/mjwagner2/ssc
    cd ssc
    git checkout solarpilot-develop
    

    Note. You can also download the repositories from GitHub as .zip files instead of cloning them. If you do that, be sure to extract them into directories named lk, wex, ssc, SolTrace, and SolarPILOT so that the makefiles can find them.

  2. The following packages are required and can be downloaded from apt-get:

    libcurl4-openssl-dev
    build-essential
    libgtk2.0-dev
    libgl1-mesa-dev
    mesa-common-dev
    freeglut3-dev
    
    sudo apt-get install <PACKAGE NAME>
    

2. Install wxWidgets-3.1.1

  1. Download wxWidgets-3.1.1 (https://www.wxwidgets.org/downloads/) source code for Linux.

We are in the process of testing wxWidgets-3.1.2. In the meantime, you can get wxWidgets-3.1.1 from https://github.com/wxWidgets/wxWidgets/releases/tag/v3.1.1: Download the wxWidgets-3.1.1.tar.bz2 file.

  1. From a terminal, unzip the file to a permanent folder like /home/<USERNAME>/wxWidgets-3.1.1:

    tar xvfj wxWidgets-3.1.1.tar.bz2
    
  2. Create a new folder in the wxWidgets folder you created in Step 2 so that each build can be installed to a different folder (remember to change /path/to to the actual path):

    cd /path/to/wxWidgets-3.1.1
    mkdir release-build
    cd release-build
    
  3. Call configure with the following options (again, remember to change /path/to to the path to your wxWidgets-3.1.1 folder):

    ../configure --prefix=/path/to/wx-3.1.1 --enable-shared=no --enable-stl=yes --enable-debug=no --with-gtk=2 --with-libjpeg=builtin --with-libpng=builtin --with-regex=builtin --with-libtiff=builtin --with-zlib=builtin --with-expat=builtin --without-libjbig --without-liblzma --without-gtkprint --with-libnotify=no --with-libmspack=no --with-gnomevfs=no --with-opengl=yes --with-sdl=no --with-cxx=11 --enable-webview
    
  4. Once configure is done, call make, and then make install.

  5. Look for wx-config in /path/to/wx-3.1.1/bin and make a note of the complete path.

  6. Create a wx-config-3 symbolic link pointing to the path you found in Step 6 so that the makefiles can find the correct wxWidgets version to run:

    sudo ln -s /path/to/wx-3.1.1/bin/wx-config /usr/local/bin/wx-config-3
    
  7. Test the wxWidgets build:

wx-config-3 --cflags

If the build was successful, you should see:

-I/home/wx-3.1.1/lib/wx/include/gtk2-unicode-static-3.1 -I/home/wx-3.1.1/include/wx-3.1 -D_FILE_OFFSET_BITS=64 -DwxDEBUG_LEVEL=0 -D__WXGTK__ -pthread

3. Install GoogleTest

The current linux Makefile assumes that you are cloning googletest into the same directory that contains your lk, wex, ssc, and SAM folders. This will eventually be replaced with an environment variable.

Clone Google Test and do an out-of-source build for the Debug or Release configuration:

git clone https://github.com/google/googletest.git
mkdir googletest/build
cd googletest/build
cmake .. -DCMAKE_BUILD_TYPE=<Debug;Release> -DCMAKE_CXX_FLAGS=-std=c++11
make -j4

If the build succeed, you should see googletest/build/lib/libgtest<d>.a.

4. Set Environment Variables

Environment variables store values for programs and processes on your computer. The SolarPILOT build script use five 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 1.

Name Value (Folder Path)
GTEST /path/to/googletest/googletest
CORETRACEDIR /path/to/SolTrace/coretrace
LKDIR /path/to/lk
WEXDIR /path/to/wex
SSCDIR /path/to/ssc

Set environment variables in your .bashrc

To conveniently set your environment variables to be set every time you open a terminal, set them in your user .bashrc file:

gedit $HOME/.bashrc

And then in the file:

export GTEST=/path/to/googletest/googletest
export CORETRACEDIR=/path/to/SolTrace/coretrace
export LKDIR=/path/to/lk
export WEXDIR=/path/to/wex
export SSCDIR=/path/to/ssc

Finally, save and close the file and:

source $HOME/.bashrc

5. Configure SSC/NLOPT

On linux systems, the library nlopt requires configuration before project building.
From spt_dev, navigate to the directory containing nlopt and call ./configure:

cd ssc/nlopt
./configure

If successful, you should see config.h header file within the nlopt directory.

6. Install LK, WEX, SSC, SolTrace, then SolarPILOT

The build requires CMake 3.12 or higher. There are two build methods:

  1. The first uses an umbrella CMakeLists.txt that bundles up all projects into a single project.

In the spt_dev folder, save the following text as CMakeList.txt:

option(SAM_SKIP_TOOLS "Skips the sdktool and tcsconsole builds" ON)
cmake_minimum_required(VERSION 3.12)

Project(solarpilot_ui)
#Project(solarpilot_api)

if(${CMAKE_PROJECT_NAME} STREQUAL "solarpilot_api")
        option(COPILOT_API "Builds library for Copilot API" ON)
endif()

if(${CMAKE_PROJECT_NAME} STREQUAL "solarpilot_ui")
	add_subdirectory(lk)
	add_subdirectory(wex)
endif()

add_subdirectory(ssc)
add_subdirectory(SolTrace/coretrace)

if(${CMAKE_PROJECT_NAME} STREQUAL "solarpilot_ui")
	add_subdirectory(SolarPILOT)
endif()

NOTE: If you change the project name to solarpilot_api, the dynamic library will be compiled for the CoPylot Python API.

To do an out-of-source build from command line for either the Debug or Release configuration:

mkdir build
cd build
cmake .. -DCMAKE_BUILD_TYPE=Release
make -j4

To build the Debug version, change the CMAKE_BUILD_TYPE to Debug.

  1. The second method builds each project separately.

For each project in order, LK, WEX, SSC, SolTrace/coretrace, SolarPILOT, do an out-of-source build from the command line for either the Debug or Release configuration:

cd <proj>
mkdir build
cd build
cmake .. -DCMAKE_BUILD_TYPE=Release
make -j4

NOTE: A fatal error like "wx/string.h no such file or directory" might be caused by an incorrect wx-config-3 symbolic link or a problem with the wxWidgets build.

6. Run the application

To run the app, go to the deploy folder at /path/to/SolarPILOT/deploy/x64/ and run ./SolarPILOT.