Cross-Compiling SQLite3 to Enable Databases on duo

The source of this requirement comes from the previous post, where we needed to store data for mosquitto message persistence, and the best storage solution is a database. So, let’s proceed with cross-compiling the widely-used SQLite3 for embedded systems.

I. Source Code Acquisition

Official website SQLite Download Page

https://www.sqlite.org/download.html

The current latest version is sqlite-autoconf-3420000.tar.gz (3.00 MiB), and we will download it.

Unpack it on Ubuntu:

tar zxvf sqlite-autoconf-3420000.tar.gz

image

Navigate to the source code directory:

cd sqlite-autoconf-3420000

II. Cross-Compilation

Create the build directory:


mkdir build

cd build

Enable the riscv cross-compilation environment:

source the cross-compilation toolchain

By typing riscv and pressing TAB, the toolchain name should auto-complete, indicating that the environment is set up.

Generate the build files:

../configure --enable-readline=no --host=riscv64-unknown-linux-musl --prefix=$(pwd)/install_cv1800b

image

After completion, modify the Makefile in the build directory to add some compilation parameters specific to the chip:

Add C/C++ compilation parameters on lines 255-256:


CFLAGS = -g -O2 -mcpu=c906fdv -march=rv64imafdcv0p7xthead -mcmodel=medany -mabi=lp64d

CPPFLAGS = -mcpu=c906fdv -march=rv64imafdcv0p7xthead -mcmodel=medany -mabi=lp64d

image

Save and exit.

Then compile and install:


make

make install

In the build directory, the install_cv1800b directory is generated.

image

Copy the executable files under bin to /usr/bin on the development board. Also, copy all dynamic libraries (.so files) under lib to /usr/lib on the development board.

Now you can use it on duo, and for application-level development, link to the libraries below and include the referenced header files.

III. Using on duo

You can check the version by running sqlite3 --version.

If you need to perform database operations from the command line, you can run sqlite3 to enter command mode, where you can create a database, add, query, update, and delete data.

image

For more details, you can enter help to see the usage.

IV. Software Package Acquisition

As usual, for the convenience of those who prefer pre-compiled packages, I provide the install directory and a compressed package for one-click installation on duo.

SQLite3 GitHub