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. Expand the sections below for the hardware you want MEL to support:

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

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.

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


National Instruments DAQmx

Download and install the NI-DAQmx 18.6 Full (32-bit & 64-bit) drivers and APIs. Ensure that the following directory exits upon completion:

C:\Program Files (x86)\National Instruments\Shared\ExternalCompilerSupport\C

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


Thalmic Labs Myo

Download the Windows SDK 0.9.0. Place the zipped folder myo-sdk-win-0.9.0 in C:/Program Files/. The full path should be:

C:/Program Files/myo-sdk-win-0.9.0/

and should contain folders bin, include, lib, etc. The Myo SDK is linked dynamically, meaning your programs will need to access myo32.dll or myo64.dll. You can either copy these files to the directories of your applications, or make a one-time copy to C:/Windows/System32 (for myo64.dll) or C:\WINDOWS\SysWOW64 (for myo32.dll) and register the DLLs in an Administrator command prompt:

C:\WINDOWS\system32> regsvr32 myo64.dll
C:\WINDOWS\SysWOW64> regsvr32 myo32.dll

Note: No, that's not a typo. The 64-bit DLL goes in system32, and the 32-bit DLL goes in SysWOW64. Thanks, Microsoft.


Generating Build Files with CMake

After you've installed all the hardware APIs you want, open an Administrator terminal 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" -DMEL_EXAMPLES=ON   # 64-bit compile (you probably want this)

or

> cmake .. -G "Visual Studio 15 2017"          # 32-bit compile

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. MEL provides the following options when building with CMake:

CMake Option Effect
EXAMPLES Builds MEL example applications
DISABLE_LOG Disables MEL's built in error logging system
BUILD_DOC Builds MEL's HTML documentation (Doxygen must be installed)

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.

-- Selecting Windows SDK version 10.0.17763.0 to target Windows 10.0.17134.
-- The C compiler identification is MSVC 19.16.27027.1
-- The CXX compiler identification is MSVC 19.16.27027.1

...

Building MEL::MEL
-- Found HIL: C:/Program Files/Quanser/QUARC/lib/win64/hil.lib
Building MEL::quanser
-- Found NIDAQmx: C:/Program Files (x86)/National Instruments/Shared/ExternalCompilerSupport/C/lib64/msvc/NIDAQmx.lib
-- Found Myo: C:/Program Files/myo-sdk-win-0.9.0/lib/myo64.lib
Building MEL::myo
Building MEL examples
-- Configuring done
-- Generating done
-- Build files have been written to: C:/Git/MEL/build

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