-
Notifications
You must be signed in to change notification settings - Fork 3
Building MEL for NI Linux Real Time
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 myRIO 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.
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 |
Linux | Download | Download |
You will need 7-Zip or similar to extract the contents of the .tar.xz
. MEL expects the compilers to be saved in C:/dev/nilrt-x64
or 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, the two most popular being Ninja and Make. Make
comes pre-installed on most Linux distros, so you should use it if your host system is Linux based. For Windows, the easiest solution is to use Ninja:
Ninja - Download
You can save ninja.exe
wherever you like (e.g. C:/bin/
), just make sure its location is added to the PATH
system variable and that it can be executed from your command prompt/terminal.
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 asbuild-quanser
,build-myrio
, 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) and plan to use the Ninja generator:
> cmake .. -G Ninja -DCMAKE_TOOLCHAIN_FILE="../cmake/nilrt-arm-toolchain.cmake" -DEXAMPLES=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. Consult the Getting Started page to see what other general options are available.
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.
Compiling with Ninja
is super simple. In the same terminal as before just call:
> ninja
or if you are using Make
:
> make
The MEL library binary will be compiled to MEL/build/libMEL.so
and example binaries will be compiled to MEL/build/examples/
. That's it!