Compile external library for C/C++
Introduction
Also, this tutorial refers to the SDK installation directory as ${SDK_DIR}.
Building external libraries is not supported. Please build the external library by referring to the information provided in this chapter. Please note that we cannot provide support even if you contact us.
Table of contents
- 1 Introduction
- 2 Table of contents
- 3 Overview
- 4 Compile C/C++ module(OpenCV)
- 5 Compile C/C++ module(Curl)
- 5.1 Prepare the compilation environment
- 5.2 Download source code
- 5.3 Run Configure
- 5.3.1 Without OpenSSL
- 5.3.2 With OpenSSL
- 5.4 Build curl
- 5.5 Deployment in AdamApp
- 5.5.1.1 Copy of library file
- 5.5.1.2 Copy of header file
- 5.5.2 Build the sample application
- 6 Compile C/C++ module(SQLite)
- 6.1 Prepare the compilation environment
- 6.2 Download source code
- 6.3 Run Configure
- 6.4 Build sqlite
- 6.5 Deployment in AdamApp
- 6.5.1.1 Copy of library file
- 6.5.1.2 Copy of header file
- 6.5.1.3 Makefile modifications
- 6.5.2 Build the sample application
- 7 Compile C/C++ module(libjpeg)
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
Setup your build environment to use SDK by using “setup_env.sh”
$ cd ${SDK_DIR}
$ source setup_env.sh ipro-ambaCV2X
"ipro-ambaCV2X" is specified, but please change it according to your environment.
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.
Install OpenCV in the “${SDK_DIR}/external/build/opencv/aarch64-linux-gnu“ directory.
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.
Then, the directory structure will be as follows.
Copy of header file
Execute the following command in the “${SDK_DIR}/external/build/opencv/aarch64-linux-gnu” directory.
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.
Delete files no longer needed
The information needed for debugging library is included in the OpenCV library you created.
We recommend that you delete this file to reduce the folder size as you do not need this to run the application.
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).
Please perform the build method according to each SDK version.
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)
Prepare the compilation environment
Setup your build environment to use SDK by using “setup_env.sh”
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.
After copying the downloaded source code (curl-7.87.0.tar.gz) to the created curl directory, extract it.
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
With OpenSSL
[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.
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.
Then, the directory structure will be as follows.
Copy of header file
Execute the following command in the “${SDK_DIR}/external/build/curl/curl-7.87.0” directory.
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).
Please perform the build method according to each SDK version.
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)
Prepare the compilation environment
Setup your build environment to use SDK by using “setup_env.sh”
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.
After copying the downloaded source code (sqlite-autoconf-3400000.tar.gz) to the created sqlite directory, extract it.
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.
Build sqlite
Build curl in the “${SDK_DIR}/external/build/sqlite/sqlite-autoconf-3400000” directory.
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.
Then, the directory structure will be as follows.
Copy of header file
Execute the following command in the “${SDK_DIR}/external/build/sqlite/sqlite-autoconf-3400000” directory.
The directory structure after copying is as follows.
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
Before building the sample app, format the SD card using the screen below. (Please confirm in advance whether the SD card can be formatted. All data on the SD card will be erased.)
Once formatting is complete, the SD card as ext (ext4) and press the Set button.
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).
Please perform the build method according to each SDK version.
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.
Compile
Compile libjpeg module using docker.
Run Docker in “${SDK_DIR}/external/build/sample/docker” directory.
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
Once copied, create a symbolic link.
Then, the directory structure will be as follows.
${SDK_DIR}/src/adamapp/jpeg_app/external/lib/aarch64-linux-gnu/libjpeg.so.9.5.0
${SDK_DIR}/src/adamapp/jpeg_app/external/lib/aarch64-linux-gnu/libjpeg.so.9
${SDK_DIR}/src/adamapp/jpeg_app/external/lib/aarch64-linux-gnu/libjpeg.so
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
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).
Please perform the build method according to each SDK version.
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.