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-3.0.13.tar.gz. In your download directory, run the following commands where, <OpenSSL_Install_Directory>
refers to the directory you want to install OpenSSL:
tar -xvzf openssl-3.0.13.tar.gz
cd openssl-3.0.13
./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-8.6.0.tar.gz. In your download directory, run the following commands, where <libcurl_Install_Directory>
refers to the directory you want to install libcurl
:
tar -xvzf curl-8.6.0.tar.gz
cd curl-8.6.0
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:
Variable | Default Value | Description |
---|---|---|
MCL_STATICLIB | OFF | If set to ON, MCL components are built as static library. |
MCL_DOC | OFF | If set to ON, MCL reference documentation is also built. |
MCL_TEST | OFF | If set to ON and if ruby is found in path MCL is built with tests. |
MCL_CONNECTIVITY | ON | If set to ON, MCL Connectivity component will also be built. |
MCL_DATA_LAKE | ON | If set to ON, MCL Data Lake component will also be built. |
MCL_DEPLOYMENT | ON | If 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_LEVEL | MCL_LOG_LEVEL_INFO | MCL 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 Level | Description |
---|---|
MCL_LOG_LEVEL_VERBOSE | Extensive details of operation are logged together with MCL_LOG_LEVEL_DEBUG level logs. |
MCL_LOG_LEVEL_DEBUG | Diagnostically helpful information are logged together with MCL_LOG_LEVEL_INFO level logs. |
MCL_LOG_LEVEL_INFO | Information for the stages of operation are logged together with MCL_LOG_LEVEL_WARN level logs. |
MCL_LOG_LEVEL_WARN | Warnings are logged together with MCL_LOG_LEVEL_ERROR level logs. |
MCL_LOG_LEVEL_ERROR | Operational errors are logged together with MCL_LOG_LEVEL_FATAL level logs. |
MCL_LOG_LEVEL_FATAL | Only fatal errors are logged. |
MCL_LOG_LEVEL_NONE | Nothing 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.
Except where otherwise noted, content on this site is licensed under the Development License Agreement.