Introduction
Also, this tutorial refers to the SDK installation directory as ${SDK_DIR}.
Table of contents
Overview
C/C++ module needs to be compiled when using external library with C/C++ version AdamApp.
Here, we navigate how to build external library for C/C++ from the environment building to module compilation.
External library used in this tutorial
OpenCV 4.7.0
Curl 7.87.0
SQLite 3.40.0
libjpeg (version : 9e)
Compile C/C++ module(OpenCV)
As a tutorial, we will compile OpenCV.
Please check the official website for details of OpenCV.
Prepare the compilation environment
OpenCV build requires "cmake", so install it.
$ sudo apt-get install cmake
Download source code
Download OpenCV source code from the URLs below.
This tutorial uses 4.7.0(opencv-4.7.0.zip).
Select the version to download according to the functions you use.
A sample Makefile and cmake file are included in the SDK for building OpenCV.
Copy the downloaded source code (opencv-4.7.0.zip) to the folder below.
${SDK_DIR}
/external/build/opencv/aarch64-linux-gnu
Customization of cmake
Customize the “${SDK_DIR}/external/build/opencv/aarch64-linux-gnu/aarch64_toolchain.cmake” file as needed.
For this tutorial, proceed without customization.
Makefile settings
Edit the second line of the “${SDK_DIR}/external/build/opencv/aarch64-linux-gnu/Makefile“ file to match the downloaded version.
This tutorial sets opencv-4.7.0.
OPENCV_DIR = opencv-4.7.0
Also, customize the build options for the OpenCV module. You can see the options by searching for "-D" in the Makefile.
Enable only the options you really need.
If unnecessary options are included, the size of the OpenCV library will be larger than necessary and it will not be possible to include it in your application.
For this tutorial, proceed without customization.
Build and install OpenCV
Build OpenCV in the “${SDK_DIR}/external/build/opencv/aarch64-linux-gnu“ directory.
$ make
Compiling OpenCV takes some time, so wait for a while.
Install OpenCV in the “${SDK_DIR}/external/build/opencv/aarch64-linux-gnu“ directory.
$ make install
Administrator rights may be required. In that case, run sudo make install.
The library is created in a “${SDK_DIR}/external/build/opencv/aarch64-linux-gnu/install“ directory.
Deployment in AdamApp
Deploy the OpenCV modules to use them with AdamApp.
Here we take “opencv_edge_detection_app” as an example.
Copy of library file
Execute the following command in the “${SDK_DIR}/external/build/opencv/aarch64-linux-gnu” directory.
$ cp -a install/lib/libopencv_world.so* ../../../../src/adamapp/opencv_edge_detection_app/external/lib/aarch64-linux-gnu
When using a shared folder and copying using Windows Explorer, symbolic links may not be copied correctly. Copy it on Linux.
reference: https://dev-partner.i-pro.com/space/TPFAQ/582320143
Then, the directory structure will appear as follows.
${SDK_DIR}/src/adamapp/opencv_edge_detection_app/external/lib/aarch64-linux-gnu/libopencv_world.so ${SDK_DIR}/src/adamapp/opencv_edge_detection_app/external/lib/aarch64-linux-gnu/libopencv_world.so.4.7.0 ${SDK_DIR}/src/adamapp/opencv_edge_detection_app/external/lib/aarch64-linux-gnu/libopencv_world.so.407
Copy of header file
Execute the following command in the “${SDK_DIR}/external/build/opencv/aarch64-linux-gnu” directory.
$ cp -r install/include/opencv4/opencv2 ../../../../src/adamapp/opencv_edge_detection_app/external/include
There is no change in the directory structure after copying.
Make sure the files are copied to the destination “${SDK_DIR}/src/adamapp/opencv_edge_detection_app/external/include/opencv2“ directory.
Build the sample application
Build the sample application "opencv_edge_detection_app" and install it on the camera (eg, it can be installed from the green frame in the image below).
See here★link★ for how to build.
Open the app screen (red frame button in the image below),
and if the following edge-detected image of the captured by the camera is displayed, it is successful.
Compile C/C++ module(Curl)
Download source code
Download libcurl source code from the URLs below.
This tutorial uses 7.87.0.
Select the version to download according to the functions you use.
Create a directory to store the downloaded source code.
$ cd ${SDK_DIR}/external/build $ mkdir curl $ cd curl
After copying the downloaded source code (curl-7.87.0.tar.gz) to the created curl directory, extract it.
$ cd ${SDK_DIR}/external/build/curl $ cp [Downloaded source code storage directory]/curl-7.87.0.tar.gz ./ $ tar -zxvf curl-7.87.0.tar.gz $ cd curl-7.87.0
Run Configure
Run in the “${SDK_DIR}/external/build/curl/curl-7.87.0“ directory.
Be sure to add the [--host] option.
Select other options according to the functions you use.
Without OpenSSL
$ ./configure --host=aarch64-linux-gnu --without-ssl
With OpenSSL
$ ./configure --host=aarch64-linux-gnu --with-ssl=[OPENSSL_DIR]
[OPENSSL_DIR] is arbitrary directory
This tutorial runs without OpenSSL.
Build curl
Build curl in the “${SDK_DIR}/external/build/curl/curl-7.87.0” directory.
$ make
Deployment in AdamApp
Deploy the curl modules to use them with AdamApp.
Here we take “update_sample_app” as an example.
Copy of library file
Execute the following command in the “${SDK_DIR}/external/build/curl/curl-7.87.0” directory.
$ cp -a lib/.libs/libcurl.so* ../../../../src/adamapp/update_sample_app/external/lib/aarch64-linux-gnu
When using a shared folder and copying using Windows Explorer, symbolic links may not be copied correctly. Copy it on Linux.
reference: https://dev-partner.i-pro.com/space/TPFAQ/582320143
Then, the directory structure will appear as follows.
${SDK_DIR}/src/adamapp/update_sample_app/external/lib/aarch64-linux-gnu/libcurl.so ${SDK_DIR}/src/adamapp/update_sample_app/external/lib/aarch64-linux-gnu/libcurl.so.4 ${SDK_DIR}/src/adamapp/update_sample_app/external/lib/aarch64-linux-gnu/libcurl.so.4.8.0
Copy of header file
Execute the following command in the “${SDK_DIR}/external/build/curl/curl-7.87.0” directory.
$ cp -r include/curl ../../../../src/adamapp/update_sample_app/external/include
There is no change in the directory structure after copying.
Make sure the files are copied to the destination ${SDK_DIR}/src/adamapp/update_sample_app/external/include/curl” directory.
Build the sample application
Build the sample application "update_sample_app" and install it on the camera (eg, it can be installed from the green frame in the image below).
See here★link★ for how to build.
Open the app screen (red frame button in the image below),
and if the string is displayed like following, it is successful.
{"r_appDataType":"0","r_appData":"CA=="}
Compile C/C++ module(SQLite)
Download source code
Download SQLite source code from the URLs below.
This tutorial uses 3.40.0.
Select the version to download according to the functions you use.
SQLite Home Page
https://www.sqlite.org/index.html
SQLite 3.40.0
Create a directory to store the downloaded source code.
$ cd ${SDK_DIR}/external/build $ mkdir sqlite $ cd sqlite
After copying the downloaded source code (sqlite-autoconf-3400000.tar.gz) to the created sqlite directory, extract it.
$ cd ${SDK_DIR}/external/build/sqlite $ cp [Downloaded source code storage directory]/sqlite-autoconf-3400000.tar.gz ./ $ tar -zxvf sqlite-autoconf-3400000.tar.gz $ cd sqlite-autoconf-3400000.tar.gz
Run Configure
Run in the “${SDK_DIR}/external/build/sqlite/sqlite-autoconf-3400000” directory.
Be sure to add the [--host] option.
Select other options according to the functions you use.
$ ./configure --host=aarch64-linux-gnu
Build sqlite
Build curl in the “${SDK_DIR}/external/build/sqlite/sqlite-autoconf-3400000” directory.
$ make
Deployment in AdamApp
Deploy the sqlite modules to use them with AdamApp.
Here we take “sqlite_app” as an example.
Copy of library file
Execute the following command in the “${SDK_DIR}/external/build/sqlite/sqlite-autoconf-3400000” directory.
$ cp -a .libs/libsqlite3.* ../../../../src/adamapp/sqlite_app/external/lib/aarch64-linux-gnu
When using a shared folder and copying using Windows Explorer, symbolic links may not be copied correctly. Copy it on Linux.
reference: https://dev-partner.i-pro.com/space/TPFAQ/582320143
Then, the directory structure will appear as follows.
${SDK_DIR}/src/adamapp/sqlite_app/external/lib/aarch64-linux-gnu/libsqlite3.a ${SDK_DIR}/src/adamapp/sqlite_app/external/lib/aarch64-linux-gnu/libsqlite3.la ${SDK_DIR}/src/adamapp/sqlite_app/external/lib/aarch64-linux-gnu/libsqlite3.lai ${SDK_DIR}/src/adamapp/sqlite_app/external/lib/aarch64-linux-gnu/libsqlite3.so ${SDK_DIR}/src/adamapp/sqlite_app/external/lib/aarch64-linux-gnu/libsqlite3.so.0 ${SDK_DIR}/src/adamapp/sqlite_app/external/lib/aarch64-linux-gnu/libsqlite3.so.0.8.6
Copy of header file
Execute the following command in the “${SDK_DIR}/external/build/sqlite/sqlite-autoconf-3400000” directory.
$ cp sqlite3.h ../../../../src/adamapp/sqlite_app/external/include
The directory structure after copying is as follows.
${SDK_DIR}/src/adamapp/sqlite_app/external/include/sqlite3.h
Makefile modifications
You need to modify the Makefile to match the SQLite .so and .a files.
In this tutorial, the SQLite library has file names of "libsqlite3.so" and "libsqlite3.a", so you will need to modify them accordingly.
Modify ${SDK_DIR}/src/adamapp/sqlite_app/Makefile as follows.
Before) ADD_LIBS+= sqlite
↓
After) ADD_LIBS+= sqlite3
Build the sample application
Build the sample application "sqlite_app" and install it on the camera (eg, it can be installed from the green frame in the image below).
See here★link★ for how to build.
Open the app screen (red frame button in the image below),
and if the following screen is displayed, it is successful.
Compile C/C++ module(libjpeg)
Build a Docker environment
Compile in Docker environment to use libjpeg in Ubuntu (64-bit) environment.
Please refer to here★link★ to build a Docker environment and create a Docker image.
Download source code
Download libjpeg source code from the URLs below.
This tutorial uses version 9e.
Select the version to download according to the functions you use.
libjpeg (version : 9e)
Place the downloaded files to “${SDK_DIR}/external/build/sample/docker/docker_volume” directory.
Update compilation instructions file
Put the compilation instructions in “${SDK_DIR}/external/build/sample/docker/docker_volume/module_compile.sh” file.
Please copy the content below.
#!/bin/sh -x HOME_PATH=/home/docker LIBJPEG_ARCHIVES=jpegsrc.v9e.tar.gz LIBJPEG_DIR=jpeg-9e ## for libjpeg cd ${HOME_PATH} tar zxf ${LIBJPEG_ARCHIVES} cd ${LIBJPEG_DIR} ./configure make
Compile
Compile sqlite module and Python module using docker.
${SDK_DIR}/external/build/sample/docker ディレクトリでDockerを実行してください。
$ docker run --rm -it --name aarch64-ubuntu -v `pwd`/docker_volume:/home/docker compile/ubuntu-rel:0.1
${SDK_DIR}/external/build/sample/docker/docker_volume/jpeg-9eにコンパイル済みモジュールが作成されます。
AdamAppに配置する
作成されたモジュールを、AdamAppで使用できるように配置します。
チュートリアルではsrc/adamapp/jpeg_appを例とします。
libjpegを配置する
libjpegライブラリは以下のディレクトリにインストールされています。
${SDK_DIR}/external/build/sample/docker/docker_volume/jpeg-9e/.libs
libjpeg.so.9.5.0
上記ファイルを、AdamAppソースディレクトリにコピーしてください。
${SDK_DIR}/src/adamapp/jpeg_app/external/lib/aarch64-linux-gnu
$ cp -r ${SDK_DIR}/external/build/sample/docker/docker_volume/jpeg-9e/.libs/libjpeg.so.9.5.0 ${SDK_DIR}/src/adamapp/jpeg_app/external/lib/aarch64-linux-gnu
コピー後のディレクトリ構成は以下のようになります。
${SDK_DIR}/src/adamapp/jpeg_app/external/lib/aarch64-linux-gnu/libjpeg.so.9.5.0
libjpegヘッダファイルは以下のディレクトリにインストールされています。
${SDK_DIR}/external/build/sample/docker/docker_volume/jpeg-9e
jconfig.h
jmorecfg.h
jpeglib.h
上記3ファイルを、AdamAppソースディレクトリにコピーしてください。
${SDK_DIR}/src/adamapp/jpeg_app/external/include
$ cp -r ${SDK_DIR}/external/build/sample/docker/docker_volume/jpeg-9e/jconfig.h ${SDK_DIR}/src/adamapp/jpeg_app/external/include $ cp -r ${SDK_DIR}/external/build/sample/docker/docker_volume/jpeg-9e/jmorecfg.h ${SDK_DIR}/src/adamapp/jpeg_app/external/include $ cp -r ${SDK_DIR}/external/build/sample/docker/docker_volume/jpeg-9e/jpeglib.h ${SDK_DIR}/src/adamapp/jpeg_app/external/include
コピー後のディレクトリ構成は以下のようになります。
${SDK_DIR}/src/adamapp/jpeg_app/external/include/jconfig.h
${SDK_DIR}/src/adamapp/jpeg_app/external/include/jmorecfg.h
${SDK_DIR}/src/adamapp/jpeg_app/external/include/jpeglib.h
サンプルアプリをビルドする
サンプルアプリ「jpeg_app」をビルドして、カメラにインストールします(例:下記画像の緑枠からインストール可能)。
ビルド方法はこちらを参照してください。
アプリ画面を開いて(下記画像の赤枠ボタン)、カメラが撮影したjpeg画像が表示されていれば成功です。
チュートリアルは以上となります。