The chat responses are generated using Generative AI technology for intuitive search and may not be entirely accurate. They are not intended as professional advice. For full details, including our use rights, privacy practices and potential export control restrictions, please refer to our Generative AI Service Terms of Use and Generative AI Service Privacy Information. As this is a test version, please let us know if something irritating comes up. Like you get recommended a chocolate fudge ice cream instead of an energy managing application. If that occurs, please use the feedback button in our contact form!
Skip to content
Insights Hub and Industrial IoT

Insights Hub drives smart manufacturing through the industrial Internet of Things. Gain actionable insights with asset and operational data and improve your processes.

MindConnect Library – Building MCL¶

This section will guide you to build MCL as a dynamic library from source code using CMake in Linux environment and also show you how to import and use MCL inside an example agent application. Although the steps are described for Linux environment, they are expected to be informative enough for other environments as well.

Helper scripts build_helper_linux.sh and build_helper_win64.bat are distributed with the source code which can be used as reference to setup your host environment and build MCL in Linux and Windows respectively.

Default implementations for replaceable modules (i.e. http client, crypto, memory and file utility) will be used. If you intend to use alternative implementation for any of the replaceable modules see Replacing MCL Modules.

Both the core component and the connectivity extension will be built. See MCL Build Options to select components to build.

These are the steps of the build process in order:

Building OpenSSL¶

Download OpenSSL package openssl-1.1.1d.tar.gz and in your download directory run the following commands where <OpenSSL_Install_Directory> refers to the directory you want to install OpenSSL:

tar -xvzf openssl-1.1.1d.tar.gz
cd openssl-1.1.1d
./config --prefix=<OpenSSL_Install_Directory> -Wl,-rpath=<OpenSSL_Install_Directory>/lib shared -fPIC
sudo make install

Now, there must be a folder <OpenSSL_Install_Directory>/include/openssl and shared objects <OpenSSL_Install_Directory>/lib/libcrypto.so and <OpenSSL_Install_Directory>/lib/libssl.so.

Building Libcurl¶

Download libcurl package curl-7.65.3.tar.gz and in your download directory run the following commands where <libcurl_Install_Directory> refers to the directory you want to install libcurl:

tar -xvzf curl-7.65.3.tar.gz
cd curl-7.65.3
LDFLAGS="-Wl,-R<OpenSSL_Install_Directory>/lib" ./configure --enable-http --with-ssl=<OpenSSL_Install_Directory> --prefix=<libcurl_Install_Directory> --without-libssh2 --disable-ftp --disable-tftp --disable-file --disable-ldap --disable-rtsp --disable-dict --disable-telnet --disable-pop3 --disable-imap --disable-smb --disable-scp --disable-sftp --disable-smtp --disable-gopher --disable-manual
sudo make install

Now, there must be a folder <libcurl_Install_Directory>/include/curl and shared object <libcurl_Install_Directory>/lib/libcurl.so.

Building MCL¶

After the dependencies of MCL are built, to build MCL, run the following commands where

<MCL_Source_Directory> refers to the directory of MCL source code (i.e. directory in which README.md, top level CMakeLists.txt and subfolders for each component exist),
<MCL_Build_Directory> refers to the intermediate directory used during build process,
<MCL_Install_Directory> refers to the directory in which build artifacts are located.

mkdir -p <MCL_Build_Directory>
cd <MCL_Build_Directory>
cmake -DCMAKE_PREFIX_PATH="<OpenSSL_Install_Directory>;<libcurl_Install_Directory>" -DCMAKE_BUILD_TYPE=RELEASE -DCMAKE_INSTALL_PREFIX:PATH=<MCL_Install_Directory> -DMCL_STATICLIB=OFF -DMCL_LOG_LEVEL=MCL_LOG_LEVEL_NONE <MCL_Source_Directory>
cmake --build . --clean-first --target install

Now, there must be folders named mcl_core, mcl_connectivity, mcl_data_lake and mcl_deployment containing MCL headers in \<MCL_Install_Directory>/include and shared objects named libmcl_core.so, libmcl_connectivity.so, libmcl_data_lake.so and libmcl_deployment.so in \<MCL_Install_Directory>/lib.

MCL Build Options¶

You can build MCL with different configurations with the options listed in the table below:

VariableDefault ValueDescription
MCL_STATICLIBOFFIf set to ON, MCL components are built as static library.
MCL_DOCOFFIf set to ON, MCL reference documentation is also built.
MCL_TESTOFFIf set to ON and if ruby is found in path MCL is built with tests.
MCL_CONNECTIVITYONIf set to ON, MCL Connectivity component will also be built.
MCL_DATA_LAKEONIf set to ON, MCL Data Lake component will also be built.
MCL_DEPLOYMENTONIf set to ON, MCL Deployment component will also be built.
MCL_CRYPTO"openssl"See "Replacing MCL Modules" section.
MCL_HTTP_CLIENT"curl"See "Replacing MCL Modules" section.
MCL_FILE_UTIL"standard"See "Replacing MCL Modules" section.
MCL_MEMORY"standard"See "Replacing MCL Modules" section.
MCL_LOG_LEVELMCL_LOG_LEVEL_INFOMCL logging level. See MCL Logging section.

MCL Logging¶

MCL logging level can be configured when building MCL by setting MCL_LOG_LEVEL option to one of the values listed in the table below:

MCL Logging LevelDescription
MCL_LOG_LEVEL_VERBOSEExtensive details of operation are logged together with MCL_LOG_LEVEL_DEBUG level logs.
MCL_LOG_LEVEL_DEBUGDiagnostically helpful information are logged together with MCL_LOG_LEVEL_INFO level logs.
MCL_LOG_LEVEL_INFOInformation for the stages of operation are logged together with MCL_LOG_LEVEL_WARN level logs.
MCL_LOG_LEVEL_WARNWarnings are logged together with MCL_LOG_LEVEL_ERROR level logs.
MCL_LOG_LEVEL_ERROROperational errors are logged together with MCL_LOG_LEVEL_FATAL level logs.
MCL_LOG_LEVEL_FATALOnly fatal errors are logged.
MCL_LOG_LEVEL_NONENothing is logged.

Scope of logging can be reduced in agent application code from the level set at build time but can not be extended. See reference documentation for details.

Building Custom Agent Application¶

MCL source code is distributed with several example agent applications. See Examples for details. To build an example agent application, you can copy the source code of one of the examples to a directory, referred as <Custom_Agent_Project_Directory>, and create a CMakeLists.txt file in that directory with the content below:

CMAKE_MINIMUM_REQUIRED(VERSION 3.10 FATAL_ERROR)

# You can change the project name.
PROJECT(CustomAgentApplication LANGUAGES C)

SET(CMAKE_C_STANDARD 99)
SET(CMAKE_C_STANDARD_REQUIRED ON)

FILE(GLOB SOURCES *.c)
LIST(APPEND AGENT_SOURCES ${SOURCES})

# You must type in the directory that MCL is installed.
SET(MCL_INSTALL_DIR "<MCL_Install_Directory>")

SET(MCL_CORE ${MCL_INSTALL_DIR}/lib/libmcl_core.so)
SET(MCL_CONNECTIVITY ${MCL_INSTALL_DIR}/lib/libmcl_connectivity.so)
SET(MCL_INCLUDE_DIRECTORY ${MCL_INSTALL_DIR}/include/)

SET(AGENT_OUTPUT_DIR ${CMAKE_BINARY_DIR}/build)
SET(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${AGENT_OUTPUT_DIR})
SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${AGENT_OUTPUT_DIR})
SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${AGENT_OUTPUT_DIR})

# You can change the name of the executable, it does not have to be the same as the project name.
ADD_EXECUTABLE(${PROJECT_NAME} ${AGENT_SOURCES})

TARGET_INCLUDE_DIRECTORIES(${PROJECT_NAME} PUBLIC ${MCL_INCLUDE_DIRECTORY})
TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${MCL_CORE} ${MCL_CONNECTIVITY})

Now, you can compile your agent application by running the following commands where <Custom_Agent_Build_Directory> refers to the build directory for your project:

mkdir -p <Custom_Agent_Build_Directory>
cd <Custom_Agent_Build_Directory>
cmake <Custom_Agent_Project_Directory>
cmake --build . --clean-first

You will find agent application executable named CustomAgentApplication in <Custom_Agent_Build_Directory>.

Building MCL In Specific Environments¶

Although the default build tool is CMake, MCL is ported to be built as part of other SDK in specific environments. You can build MCL as part of an mbedOS application by importing MCL as a library to your application in mbedOS development environment. You can integrate MCL to Sony Spresense environment to be built together with Sony Spresense SDK by following the document Sony Spresense Guide provided with MCL source code.