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):
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.
./configure --host=mipsel-linux --target=mipsel-linux --prefix=/home/jaufranc/edev/sqlite-mips
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"
sqlite size is now 54.08KB and libsqlite3.so.0.8.6 595.34KB.