Introduction
Also, this tutorial refers to the SDK installation directory as ${SDK_DIR}.
Table of contents
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.
Code Block |
---|
$ 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.
Code Block |
---|
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.
Note |
---|
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.
Code Block |
---|
$ make |
Info |
---|
Compiling OpenCV takes some time, so wait for a while. |
Install OpenCV in the “${SDK_DIR}/external/build/opencv/aarch64-linux-gnu“ directory.
Code Block |
---|
$ make install |
Info |
---|
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.
Code Block |
---|
$ cp -a install/lib/libopencv_world.so* ../../../../src/adamapp/opencv_edge_detection_app/external/lib/aarch64-linux-gnu |
Note |
---|
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 be as follows.
Code Block |
---|
${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.
Code Block |
---|
$ 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 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.
Code Block |
---|
$ 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.
Code Block |
---|
$ 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
Code Block |
---|
$ ./configure --host=aarch64-linux-gnu --without-ssl |
With OpenSSL
Code Block |
---|
$ ./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.
Code Block |
---|
$ 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.
Code Block |
---|
$ cp -a lib/.libs/libcurl.so* ../../../../src/adamapp/update_sample_app/external/lib/aarch64-linux-gnu |
Note |
---|
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 be as follows.
Code Block |
---|
${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.
Code Block |
---|
$ 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 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.
Code Block |
---|
$ 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.
Code Block |
---|
$ 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.
Code Block |
---|
$ ./configure --host=aarch64-linux-gnu |
Build sqlite
Build curl in the “${SDK_DIR}/external/build/sqlite/sqlite-autoconf-3400000” directory.
Code Block |
---|
$ 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.
Code Block |
---|
$ cp -a .libs/libsqlite3.* ../../../../src/adamapp/sqlite_app/external/lib/aarch64-linux-gnu |
Note |
---|
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 be as follows.
Code Block |
---|
${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.
Code Block |
---|
$ cp sqlite3.h ../../../../src/adamapp/sqlite_app/external/include |
The directory structure after copying is as follows.
Code Block |
---|
${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 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 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.
Code Block |
---|
#!/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 using docker.
Run Docker in “${SDK_DIR}/external/build/sample/docker” directory.
Code Block |
---|
$ docker run --rm -it --name aarch64-ubuntu -v `pwd`/docker_volume:/home/docker compile/ubuntu-rel:0.1 |
The compiled module is created in “${SDK_DIR}/external/build/sample/docker/docker_volume/jpeg-9e”.
Deployment in AdamApp
Deploy the modules to use them with AdamApp.
Here we take “${SDK_DIR}/src/adamapp/jpeg_app” as an example.
Deployment in AdamApp
libjpeg module is installed in the following directory.
${SDK_DIR}/external/build/sample/docker/docker_volume/jpeg-9e/.libs
libjpeg.so.9.5.0
Copy the above file to the AdamApp source directory.
${SDK_DIR}/src/adamapp/jpeg_app/external/lib/aarch64-linux-gnu
Code Block |
---|
$ 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 |
Then, the directory structure will be as follows.
${SDK_DIR}/src/adamapp/jpeg_app/external/lib/aarch64-linux-gnu/libjpeg.so.9.5.0
libjpeg header files are installed in the following directory.
${SDK_DIR}/external/build/sample/docker/docker_volume/jpeg-9e
jconfig.h
jmorecfg.h
jpeglib.h
Copy the above 3 files to the AdamApp source directory.
${SDK_DIR}/src/adamapp/jpeg_app/external/include
Code Block |
---|
$ 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 |
Then, the directory structure will be as follows.
${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
Build the sample application
Build the sample application "jpeg_app" and install it on the camera (eg, it can be installed from the green frame in the image below).
See here for how to build.
Open the app screen (red frame button in the image below), and if the image of the captured by the camera is displayed, it is successful.