Skip to content

Building MEL for Windows

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

Note: This guide assumes you've already downloaded cmake, git, and cloned the MEL master repository (see Getting Started).

Required Setup and Installation

You will need a compatible Microsoft Visual C++ (MSVC) compiler. While other compilers exist (MinGW, Clang, etc.), the majority of the hardware API's MEL leverages were built with MSVC and thus can only be linked against under MSVC. You have two options for aquiring MSVC:

  1. Download the the minimum required build tools (recommended for MEL-flavored VS Code)
> choco install visualstudio2017-workload-vctools
  1. Download the full Visual Studio Community IDE
> choco install visualstudio2017-workload-nativedesktop

Hardware Specific Setup

MEL's CMake build system automatically scans your system to determine what hardware APIs you have installed and thus what hardware it can build modules for. Therefore, if you intend to use a particular DAQ or device in MEL, you need to have the correct software installed.

Quanser HIL (Q2-USB, Q8-USB, Q-PID)

MEL requires that you have Quanser's HIL SDK installed. The SDK contains the necessary device drivers, C/C++ headers and static libraries. There are two options for obtaining the SDK: 1) as a part of Quanser's QUARC MATLAB/Simulink software, or 2) as a standalone installation obtained by contacting Quanser directly. You likely received one of these with your device.

Note: MEL Quanser support has no dependency on MATLAB/Simulink, but QUARC may require that they are installed to successfully complete its own installation. The HIL SDK standalone can be installed without MATLAB present.

After installing, ensure that the HIL C/C++ headers and static libraries are located in the following locations:

C:/Program Files/Quanser/QUARC/include      # header files
C:/Program Files/Quanser/QUARC/lib/windows  # 32-bit libraries
C:/Program Files/Quanser/QUARC/lib/win64    # 64-bit libraries

or

C:/Program Files/Quanser/HIL SDK/include      # header files
C:/Program Files/Quanser/HIL SDK/lib/windows  # 32-bit libraries
C:/Program Files/Quanser/HIL SDK/lib/win64    # 64-bit libraries

Note: MAHI Lab members can the HIL SDK in the MAHI Box Drive

National Instruments DAQmx

Note: MEL support for NI DAQmx is currently a work in progress. Use with caution.

Download the NI-DAQmx 18.6 Full (32-bit & 64-bit) drivers and APIs.

You may also want to ensure that your Quanser hardware is successfully recognized by Windows by checking for its existence in Device Manager under Universal Serial Bus controllers when it is plugged in and powered on.

Generating Build Files with CMake

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-quanser, build-myrio, etc.

Now we call CMake to generate our build files. You must pass the -DQUANSER=ON option to tell CMake to link MEL to the HIL SDK. More than likely you will want to use the following command:

> cmake .. -G "Visual Studio 15 2017 Win64" -DQUANSER=ON -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, and -D[OPT]=ON turns the specified option on. Consult the Getting Started page to see what other general CMake 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.

Building

There are a couple of options here. The easiest is to let CMake's build command do all the hard work. In the same terminal as before:

> cmake --build . --config Release

Under the hood, this calls the MSVC compiler to build MEL in the Release configuration. You could also use Debug here as well if you wanted to use that configuration instead.

The other option is to just open the generated MEL.sln file located in the MEL/build folder, with which you can use Visual Studio's GUI interface to build MEL. You can find multiple tutorials for using Visual Studio online.

In either case, the MEL library binary will be compiled to MEL/build/Release/MEL.dll and example binaries will be compiled to MEL/build/examples/Release/*.exe. To run examples, you will need to ensure that the examples can access MEL.dll. The easiest way to do this is to move MEL.dll to the same location as the example binaries. A more permanent solution is to add MEL.dll to the globally visible location C:/Windows/System32 and register it.

Note: If you have the MOVE_BINS CMake option enabled, MEL.lib will be moved to MEL/lib/ and MEL.dll and example/test applications will be moved to MEL/bin after compilation. This is convenient if you only intend to build MEL for a single platform. If you are building for multiple platforms (e.g. cross compiling multiple NI architectures), this is not a good idea as the binaries will overwrite and or conflict with each other.

Clone this wiki locally