Skip to content

Building MEL for NI Linux Real Time

Evan Pezent edited this page Feb 24, 2019 · 19 revisions

Note: This guide assumes you've already downloaded cmake, git, and cloned the MEL master repository (see Getting Started). It also assumes you have installed the appropriate device drivers and software from National Instruments (see Installing NI Software).

Note for DAQ Users: Using MEL with National Instruments embedded devices running Linux Real-Time (LRT) is slightly different than with plug-and-play DAQs like Quanser's Q8-USB or NI's own DAQmx devices. Where as with those devices code is compiled for and run on a host PC like Windows, the code you write for NI LRT devices is actually run on the device itself. In a nutshell, code is written on a host development computer (Windows or Linux) and then compiled to a binary library or executable using NI's provided cross compiler. This binary is not executed on the host, but is instead transfered to the target NI device where finally it can be executed.

Required Setup and Installation

To build MEL for National Instruments embedded devices running real-time Linux, you will need the appropriate cross-compiler from NI:

Host System NI LRT x64 (cRIO) NI LRT ARM (myRIO)
Windows Download Download

You will need 7-Zip or similar to extract the contents of the .tar.xz.

> choco install 7zip

MEL expects the x64 and ARM compilers to be saved in the following directories, respectively:

C:/dev/nilrt-x64
C:/dev/nilrt-arm

both of which should contain sysroots/, relocate_sdk.py, etc:

You will also need a CMake compatible build system for the GNU-based cross compiler. For Windows, the easiest solution is to use Ninja:

> choco install ninja

Generating Build Files

Open command prompt in the root MEL folder (e.g. C:/Git/MEL/) and run the following commands:

> mkdir build  # make new directory for our out-of-place build
> cd build     # change directory to ./MEL/build

Note: Here we have named our build folder build. We could have named this folder anything, and if you plan to build MEL for multiple devices/platforms, it's suggested you use a unique name such as build-nilrt-arm, build-msvc-x64, etc.

Now we call CMake to generate our build files. We must tell CMake that we wish to use a NI cross compiler. We do this by defining the variable CMAKE_TOOLCHAIN_FILE to one of the two shipped with MEL. For example, if you're targeting myRIO (NI LRT ARM):

> cmake .. -G Ninja -DCMAKE_TOOLCHAIN_FILE="../cmake/nilrt-arm-toolchain.cmake" -DMEL_EXAMPLES=ON 

Breaking these commands down, cmake .. calls CMake and tells it to look one directory up for CMakeLists.txt, -G "GENERATOR STRING" sets the generator, -DCMAKE_TOOLCHAIN_FILE="..." sets the toolchain file, and -D[OPT]=ON turns the specified option on. MEL provides the following options when building with CMake:

CMake Option Effect
MEL_EXAMPLES Builds MEL example applications
MEL_DISABLE_LOG Disables MEL's built in error logging system
MEL_BUILD_DOC Builds MEL's HTML documentation (Doxygen must be installed)

The CMake output should look something like this:

-- The C compiler identification is GNU 6.3.0
-- The CXX compiler identification is GNU 6.3.0

...

Building MEL::MEL
Building MEL::myrio
Building MEL examples
-- Configuring done
-- Generating done
-- Build files have been written to: C:/Git/MEL/build

Here you can see that the core MEL library, MEL::MEL will be built. In addition, since we are compiling for NI LRT ARM, the MEL::myrio sub-module library will be built.

Once CMake has completed, the build folder will be populated with all of the necessary build files among other CMake specific files. Next, we move on to building MEL from the generated files.

Building and Installing

In the same terminal as before:

> cmake --build . --target install --config Release

Under the hood, this calls Ninja and the NI cross-compiler to build MEL in the Release configuration. It then installs MEL's libraries, header files, and examples to your system in either C:/Program Files/ or C:/Program Files (x86)/. You may also wish to build and install the Debug configuration as well:

> cmake --build . --target install --config Debug