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.
Jean-Luc started CNX Software in 2010 as a part-time endeavor, before quitting his job as a software engineering manager, and starting to write daily news, and reviews full time later in 2011.
Support CNX Software! Donate via cryptocurrencies, become a Patron on Patreon, or purchase goods on Amazon or Aliexpress
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
aargh – your stylesheets or whatever are doing this to my comments as well!
should be ‘- -‘ (two normal dashes) not ‘–‘ (one em-dash)
@ J^n
Thanks for letting me know. I’ve corrected it in my post using different tags.