Following my blog entry about Databases for Linux Embedded Systems, here are the instructions to cross-compile Oracle Berkeley DB.
First download the source code of the latest version of Berkeley DB (version 11gR2 – 18.104.22.168.25). You’ll need to register on Oracle website first on the download page http://www.oracle.com/technetwork/database/berkeleydb/downloads/index.html to download http://download.oracle.com/otn/berkeley-db/db-5.1.25.tar.gz (with AES encryption) or http://download.oracle.com/otn/berkeley-db/db-5.1.25.NC.tar.gz (if you don’t need encryption).
Extract the source code:
tar xzvf ../Downloads/db-5.1.25.tar.gz
Configure and build the source code. I’ll use mipsel-linux-gcc, but any other cross-compiler could be used.
../dist/configure –host=mipsel-linux CC=mipsel-linux-gcc RANLIB=mipsel-linux-ranlib STRIP=mipsel-linux-strip AR=mipsel-linux-ar –prefix=/home/jaufranc/edev/lib/db-11g
The full berkeley DB package is 79MB:
[email protected]:~/edev/lib/db-11g$ du –max-depth=1 -h
However, you won’t need the include and docs directory in your embedded target. So you do not need to copy those. You may or may need the utilities in the bin file. The lib diirectory contains two versions of the static library (why?) and one dynamic library libdb-5.1.so (1.8MB).
Using CFLAGS=”-Os” at the configure step above will slightly decrease the size of the library (1.7MB).
For further size reduction, add –enable-smallbuild (equivalent to –disable-cryptography, –disable-hash, –disable-queue, –disable-replication, and –disable-verify) in the configure script as follows:
../dist/configure –host=mipsel-linux CC=mipsel-linux-gcc RANLIB=mipsel-linux-ranlib STRIP=mipsel-linux-strip AR=mipsel-linux-ar –enable-smallbuild –prefix=/home/jaufranc/edev/lib/db-11g CFLAGS=”-Os”
The size of the dynamic library (libdb-5.1.so) is decrease to 938KB and the bin directory to 288KB.
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.