Cross compiling SQLite for ARM and MIPS

Following my blog entry about Databases for Linux Embedded Systems, here are the instructions to cross-compile SQlite.

First download the latest version of SQLite amalgamation with autoconf script (version 3.75):

wget http://www.sqlite.org/sqlite-autoconf-3070500.tar.gz

Extract the source code:

tar xzvf sqlite-autoconf-3070500.tar.gz

Configure and build the source code. I’ll use mipsel-linux-gcc, but any other cross-compiler could be used.

cd sqlite-autoconf-3070500
./configure --host=mipsel-linux --target=mipsel-linux --prefix=/home/jaufranc/edev/sqlite-mips
make
make install

At this point the library is correctly configured and installed, so you’d just need to copy the relevant files to your target board (skip include and share directories and  libsqlite3.a) .

Let’s check the size of the required files:

ls -l ../sqlite-mips/bin/
-rwxr-xr-x 1 jaufranc jaufranc 125513 2011-03-14 14:21 sqlite

ls -l ../sqlite-mips/lib/libsqlite3.so.0.8.6
-rwxr-xr-x 1 jaufranc jaufranc 2087584 2011-03-14 14:21 ../sqlite-mips/lib/libsqlite3.so.0.8.6

sqlite binary is 122.57KB and the dynamic library 2038.65KB.

Let’s see if we can optimize the binary size with compilation flags and by disabling some unnecessary features.

The first thing to add is CFLAGS=”-Os” to your compilation flags as it will decrease the size by half.

Then if you don’t need it, you could disable R-Tree support (Remove -DSQLITE_ENABLE_RTREE in Makefile.in) and Full Text Search (Remove -DSQLITE_ENABLE_FTS3  in Makefile.in) which will save about 100KB extra.

Instead of using make install, type make install-strip to save more space as it would call mipsel-linux-strip.

Configure, build and install SQLite again:

./configure --host=mipsel-linux --target=mipsel-linux --prefix=/home/jaufranc/edev/sqlite-mips CFLAGS="-Os"
make
make install-strip

sqlite size is now 54.08KB and libsqlite3.so.0.8.6 595.34KB.

Share this:

Support CNX Software! Donate via cryptocurrencies, become a Patron on Patreon, or purchase goods on Amazon or Aliexpress

ROCK 5 ITX Rockchip RK3588 mini-ITX motherboard
Subscribe
Notify of
guest
The comment form collects your name, email and content to allow us keep track of the comments placed on the website. Please read and accept our website Terms and Privacy Policy to post a comment.
3 Comments
oldest
newest
J^n
J^n
12 years ago

Hi there – thanks for this, but I think your code snippets fail to distinguish between ‘-‘ and ‘–‘; the latter seems to be encoded as a single character. For instance, your first bit of code should be something like:

./configure –host=mipsel-linux –target=mipsel-linux –prefix=/home/jaufranc/edev/sqlite-mips

not
./configure –host=mipsel-linux –target=mipsel-linux –prefix=/home/jaufranc/edev/sqlite-mips

J^n
J^n
12 years ago

aargh – your stylesheets or whatever are doing this to my comments as well!

should be ‘- -‘ (two normal dashes) not ‘–‘ (one em-dash)

Boardcon Rockchip RK3588S SBC with 8K, WiFI 6, 4G LTE, NVME SSD, HDMI 2.1...