How to cross compile the Berkeley DataBase - Step by Step Guide

Introduction

This tutorial introduces the way to cross compile the Oracle Berkeley DB on an GNU Linux embedded platform. The host machine will be a PC on which a GNU Linux distribution is installed. The embedded platform might be constructed on top of one of the following architectures: arm, mips, mipsel, ppc or sparc.

The web site dealing with the Oracle Berkeley DB can be reached at the following URL: http://www.oracle.com/database/berkeley-db/db/index.html. The latest available release at the time of writing of this tutorial is 4.6.21 (no date).

All the releases can be downloaded at the following URL: http://www.oracle.com/technology/software/products/berkeley-db/index.html, downloading release 4.6.21 can be done by typing the following command:

wget http://download.oracle.com/berkeley-db/db-4.6.21.tar.gz

Overview

Oracle Berkeley DB is the industry-leading open source, embeddable database engine that provides developers with fast, reliable, local persistence with zero administration. Oracle Berkeley DB is a library that links directly into your application. Your application makes simple function calls, rather than sending messages to a remote server, eliminating the performance penalty of client-server architectures. Oracle Berkeley DB eliminates the overhead of SQL query processing, enabling applications with predictable access patterns to run faster.

Prerequisites

To cross compile the Oracle Berkeley DB, you need either a cross compiler, or an emulated Linux running on top of a virtualization software such as QEMU, matching your specific target platform.

If you wish to build yourself such a cross compiler, you should read the crosstool tutorial. There you will find all the information you need in order to build a C, C++ 4.1 GNU compiler for an ARM platform.

If you prefer to setup an ARM Debian system on top of a traditional Ubuntun distro (after all you are an hacker, aren't you?), have a look at How to setup an ARM Debian on Ubuntu tutorial in this wiki.

In general, DB does not need specific dependencies.

Cross compilation process

Using a cross compiler

Assumptions

During the process, we will refer to the cross toolchain with xxx-yyy-linux-gnu prefix. For example, the C compiler is called xxx-yyy-linux-gnu-gcc. That is applied on all the tools and utilities such gcc, g++, ar, ld, etc.

We will also assume that bin, include, lib and libexec folders of the cross toolchain are accessible through the PATH variable environment in order to work with the compilers from any place in the file system.

Finally, we assume that it is intalled in the following folder:
/opt/crosstool/gcc-4.1.2-glibc-2.3.2/xxx-yyy-linux-gnu.

Organization

As mentioned above, the release being cross compiled is 4.6.21. The tar.gz file will then be extracted under the /opt/external_packages/db/4.6.21/source folder and the results of the compilation will be stored under the /opt/external_packages/db/4.6.21/compiled/xxx-yyy-linux-gnu folder.

The files resulting from the cross compilation are listed here (note that the docs folder has been voluntary deleted):

.:
total 12
drwxr-xr-x 2 root root 4096 2008-02-07 16:27 bin
drwxr-xr-x 2 root root 4096 2008-02-07 16:27 include
drwxr-xr-x 2 root root 4096 2008-02-07 16:27 lib

./bin:
total 196
-r-xr-xr-x 1 root root  6696 2008-02-07 16:27 db_archive
-r-xr-xr-x 1 root root  8156 2008-02-07 16:27 db_checkpoint
-r-xr-xr-x 1 root root 20512 2008-02-07 16:27 db_codegen
-r-xr-xr-x 1 root root  8236 2008-02-07 16:27 db_deadlock
-r-xr-xr-x 1 root root 10536 2008-02-07 16:27 db_dump
-r-xr-xr-x 1 root root 15212 2008-02-07 16:27 db_hotbackup
-r-xr-xr-x 1 root root 20004 2008-02-07 16:27 db_load
-r-xr-xr-x 1 root root 54688 2008-02-07 16:27 db_printlog
-r-xr-xr-x 1 root root  8164 2008-02-07 16:27 db_recover
-r-xr-xr-x 1 root root  9456 2008-02-07 16:27 db_stat
-r-xr-xr-x 1 root root  7316 2008-02-07 16:27 db_upgrade
-r-xr-xr-x 1 root root  8000 2008-02-07 16:27 db_verify

./include:
total 152
-r--r--r-- 1 root root  38220 2008-02-07 16:20 db_cxx.h
-r--r--r-- 1 root root 107167 2008-02-07 16:20 db.h

./lib:
total 9712
-rw-r--r-- 1 root root 1775466 2008-02-07 16:27 libdb-4.6.a
-rw-r--r-- 1 root root     853 2008-02-07 16:25 libdb-4.6.la
-rwxr-xr-x 1 root root 1183284 2008-02-07 16:25 libdb-4.6.so
lrwxrwxrwx 1 root root      12 2008-02-25 15:39 libdb-4.so -> libdb-4.6.so
-rw-r--r-- 1 root root 1775466 2008-02-07 16:27 libdb.a
-rw-r--r-- 1 root root 1928820 2008-02-07 16:27 libdb_cxx-4.6.a
-rw-r--r-- 1 root root    1602 2008-02-07 16:25 libdb_cxx-4.6.la
-rwxr-xr-x 1 root root 1313651 2008-02-07 16:25 libdb_cxx-4.6.so
lrwxrwxrwx 1 root root      16 2008-02-25 15:39 libdb_cxx-4.so -> libdb_cxx-4.6.so
-rw-r--r-- 1 root root 1928820 2008-02-07 16:27 libdb_cxx.a

Cross compilation

Step 1

Install the db software by untaring it in the /opt/external_packages/db/4.6.21/source folder and then cd to this directory.

Note:

All the below directories and files must be moved from the db-4.6.21 folder to the parent folder (/opt/external_packages/db/4.6.21/source)

btree
common
db_deadlock
db_printlog
docs_src
hsearch
mutex
php_db4
tcl
build_brew
crypto
db_dump
db_recover
env
java
os
qam
test
build_s60
cxx 
db_dump185    
dbreg        
examples_c     
libdb_java  
os_brew     
README      
test_micro
build_unix     
db             
db_hotbackup  
db_stat      
examples_cxx   
LICENSE     
os_qnx      
rep         
txn
build_vxworks  
db185          
dbinc         
db_upgrade   
examples_java  
lock        
os_s60      
repmgr      
xa
build_wince    
db_archive     
dbinc_auto    
db_verify    
fileops        
log         
os_vxworks  
rpc_client
build_windows  
db_checkpoint  
db_load       
dist         
hash           
mod_db4     
os_windows  
rpc_server
clib           
db_codegen     
dbm           
docs         
hmac           
mp          
perl        
sequence

Step 2

We want to cross compile db with the following parameters:

  • bifgile enabled
  • cryptography enabled
  • hash enabled
  • mutex support enabled
  • queue access method enabled
  • database replication enabled
  • statistics enabled
  • database verification enabled
  • DB 1.85 compatibility disabled
  • C++ API build enabled
  • debug disabled
  • logs read operations disabled
  • logs write operations disabled
  • java API disabled
  • DB for MinGW disabled
  • fine-grained lock manager disabled
  • O_DIRECT flag for direct I/O disabled
  • POSIX standard mutexes disabled
  • thread self disabled
  • thread api disabled
  • rpc disabled
  • smallbuild disabled
  • tcl API disabled
  • test suite disabled
  • Unix International mutexes disabled
  • umrw disabled

Then we type the following commands:

cd build_unix

../dist/configure --host=xxx-yyy-linux-gnu --enable-cxx --prefix=/opt/external_packages/db/4.6.21/compiled/xxx-yyy-linux-gnu

Finally, the Makefile is created.

Step 3

To compile and install db, type successively make and make install. You should find the directories and files listed in section IV.1.2 under /opt/external_packages/db/1.2.3/compiled/xxx-yyy-linux-gnu.

With QEMU

This section is not yet available.

Download

  • arm-db-4.6.21-tar.gz

You may consult this section if you want to download the Oracle Berkeley DB already cross compiled for your target platform if it is available. You can also contribute to expand the crosscompile.org community by uploading your own results in the case a given platform is not already supported.

Supported platforms

arm-unknown-linux-gnu


Written by David Sayada.

Edit History Last Modified March 10, 2008