Skip to content

MindConnect Library – Getting started for Windows

Prerequisites

  • Visual Studio 2015 with Universal Windows Platform development and Desktop development with C++ workloads is installed on your machine.

Preparations

This section describes how to install the tools and libraries required for building the MindConnect Library.

  • Perl
  • CMake version 3.5 or higher
  • OpenSSL version 1.0.2q or higher (must be 1.0.x)
  • libcurl version 7.52.1 or higher up to 7.60.x

Info

These instructions are based on CMake 3.14.4. The required versions of the tools and libraries may vary if a different version of Visual Studio is used.

Installing Perl

  1. Download Strawberry Perl from http://strawberryperl.com.
  2. Run the installation.
  3. Open a new command line window and enter the following command:

    1
    perl –version
    

    The output should look as shown below.

    Perl Version

    Info

    The command line window must be opened after the installation.

Installing CMake

  1. Download CMake version 3.5 or higher from https://cmake.org/download/.
  2. Use the installer and make sure to add CMake to the system PATH. CMake Installer
  3. Open a new command line window and enter the following command:

    1
    cmake –-version
    

    The output should look as shown below.

    CMake Version

    Info

    The command line window must be opened after the installation.

Compiling OpenSSL

  1. Download openssl-1.0.2q.zip (or a higher version) from https://github.com/openssl/openssl/releases.
  2. Unpack the downloaded file into a folder of your choice {OpenSSL_dir}.
  3. Open the VS2015 x64 Native Tools Command Prompt.

    Hint

    If you can't find this particular command prompt, open the Visual Studio Installer and make sure that you have installed the Visual C++ features for Visual Studio 2015.

  4. Change into {OpenSSL_dir} and configure the compiler as well as the path to install OpenSSL into.

    1
    2
    3
    cd {OpenSSL_dir}
    mkdir build
    perl Configure VC-WIN64A --prefix={OpenSSL_dir}\build\openssl --openssldir={OpenSSL_dir}\build\ssl
    
    1
    2
    3
    cd C:\MCL\openssl-OpenSSL_1_0_2q
    mkdir build
    perl Configure VC-WIN64A --prefix=C:\MCL\openssl-OpenSSL_1_0_2q\build\openssl --openssldir=C:\MCL\openssl-OpenSSL_1_0_2q\build\ssl
    
  5. Build the make files.

    1
    ms\do_win64a
    
  6. Build the library and install it into the directory given by the --prefix parameter.

    1
    2
    nmake -f ms\ntdll.mak
    nmake -f ms\ntdll.mak install
    

Compiling libcurl

  1. Download curl-7.52.1.zip (or a higher version) from https://curl.haxx.se/download/.
  2. Unpack the downloaded file into a folder of your choice {curl_dir}.
  3. Open a new window of the VS2015 x64 Native Tools Command Prompt.
  4. Prepare a build directory inside {curl_dir} and open it.

    1
    2
    3
    cd {curl_dir}
    mkdir build
    cd build
    
    1
    2
    3
    cd C:\curl-7.52.1
    mkdir build
    cd build
    
  5. Set the path to OpenSSL and Visual Studio 2015 environment variables, with the Visual Studio 2015 directory {VS_dir}.

    1
    2
    set PATH=%PATH%;{OpenSSL_dir}\build\openssl
    "{VS_dir}\VC\vcvarsall.bat"
    
    1
    2
    set PATH=%PATH%;C:\MCL\openssl-OpenSSL_1_0_2q\build\openssl
    "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat"
    
  6. Build libcurl replacing {curl_dir} by the libcurl directory.

    1
    2
    cmake .. -G"Visual Studio 14 2015 Win64" -DHTTP_ONLY=ON -DCMAKE_USE_OPENSSL=ON -DCMAKE_INSTALL_PREFIX={curl_dir}\build\install
    cmake --build . --target install --config Release
    

Building MindConnect Library

  1. Download the MindConnect Library from SIOS.
  2. Unpack the downloaded file into a folder of your choice {MCL_build_dir}.
  3. Open a new window of the VS2015 x64 Native Tools Command Prompt.
  4. Copy the content of {curl_dir}\build\install and {OpenSSL_dir}\build\openssl into {MCL_build_dir}.

    1
    2
    3
    cd {MCL_build_dir}
    Xcopy /S {curl_dir}\build\install {MCL_build_dir}\curl\
    Xcopy /S {OpenSSL_dir}\build\openssl {MCL_build_dir}\openssl\
    
  5. Move the files libeay32.dll and ssleay32.dll to {MCL_build_dir}\openssl\lib.

    1
    2
    move {MCL_build_dir}\openssl\bin\libeay32.dll {MCL_build_dir}\openssl\lib\
    move {MCL_build_dir}\openssl\bin\ssleay32.dll {MCL_build_dir}\openssl\lib\
    
  6. Copy both moved files into {MCL_build_dir}\curl\bin\.

    1
    2
    Xcopy {MCL_build_dir}\openssl\lib\libeay32.dll {MCL_build_dir}\curl\bin\
    Xcopy {MCL_build_dir}\openssl\lib\ssleay32.dll {MCL_build_dir}\curl\bin\
    
  7. Delete {MCL_build_dir}\openssl\bin.

    1
    rmdir /Q /S {MCL_build_dir}\openssl\bin
    
  8. Create a file build_mcl.bat inside {MCL_build_dir} with the content below. Replace {MCL_folder} by the folder name of the extracted MindConnet Library files.

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    rem Set directory variables
    set MCL_SOURCE_DIR=%~dp0\{MCL_folder}
    set CMAKE_DIR=%~dp0\cmake
    set OPENSSL_DIR=%~dp0\openssl
    set CURL_DIR=%~dp0\curl
    set BUILD_DIR=%~dp0\cmake_vs_build
    rem Create build directory if it doesn't exist
    if not exist %BUILD_DIR% mkdir %BUILD_DIR%
    cd %BUILD_DIR%
    rem Clear build directory content
    for /F "delims=" %%i in ('dir /b') do (rmdir "%%i" /s/q || del "%%i" /s/q)
    rem Add to path
    set PATH=%PATH%;%CURL_DIR%;%CMAKE_DIR%;%OPENSSL_DIR%
    rem Generate a Visual Studio solution 
    cmake -G"Visual Studio 14 2015 Win64" -DCMAKE_BUILD_TYPE=Release -DMCL_STATICLIB=OFF -DMCL_USE_LIBCURL=ON -DMCL_USE_OPENSSL=ON -DMCL_CREATE_DOXYGEN=OFF -DMCL_TESTING=OFF -DMCL_LOG_UTIL_LEVEL=255 %MCL_SOURCE_DIR%
    cmake --build . --target mc
    
  9. Run the batch process.

    1
    build_mcl.bat
    

    The MindConnect Libraries mcl.lib and mc.dll as well as copies of OpenSSL and libcurl are created inside {MCL_build_dir}\cmake_vs_build\build\Release.

Building a Custom Agent Application

  1. Open the MindConnect Library Visual Studio 2015.
  2. Create a new solution called CustomAgent and add customAgent.c to the project.
  3. Open the Solution Explorer of Visual Studion 2015 using CTRL+ALT+L.
  4. Right-click on the project name in the Solution Explorer and select Properties.
  5. Set Configuration to "All Configurations", Platform to "x64".
  6. Open the General tab in the C/C++ configuration properties.
  7. Add the include directory of the extracted MindConnect Library folder to Additional Include Directories.
  8. Open the General tab in the Linker configuration properties.
  9. Add the lib directory of the extracted MindConnect Library folder to Additional Library Directories.
  10. Open the Input tab in the Linker configuration properties.
  11. Add mc.lib to Additional Dependencies.
  12. Copy the files libcurl.dll, libeay32.dll, ssleay32.dll, and mc.dll from the MindConnect Library Release folder into the directory with the custom agent executable.
  13. Build the solution.

Replacing MindConnect Library Modules with Custom Implementations

The following table lists the modules of the MindConnect Library project which can be replaced by custom implementations:

Modules Description
memory.h Implements memory related functions. If not specified otherwise, alloc, calloc, realloc and free are used from the standard library.
random.h Uses the random generator from the standard library.
security.h Provides several functions which implement calculations like SHA256, MD5, RSA key generation from OpenSSL's crypto library.
http_client.h Sends an HTTP requests to MindSphere using libcurl. Custom implementations must fulfill the same security requirements with respect to TLS v1.2. MindSphere's certificate must be validated during the SSL handshaking procedure.

For replacing a module, keep the original *.h file and replace its implementation file *.c with the same name.

Any questions left?

Ask the community


Except where otherwise noted, content on this site is licensed under the MindSphere Development License Agreement.