Building and Using Berkeley DB XML Applications on UNIX/POSIX Systems

Building C++ Applications
Building Java Applications

Any application which uses Berkeley DB XML, regardless of language API used, relies on four libraries: Berkeley DB XML, Berkeley DB, XQilla and Xerces C++. When compiling, the include files from these packages must be available, and the libraries must be included when linking the application.

When running an application, each of the shared libraries must be located by the dynamic linker, usually controlled by system settings and the LD_LIBRARY_PATH environment variable. This applies to both C++ and Java applications. See Dynamic shared libraries for more information

Building C++ Applications

Assuming Berkeley DB XML, Berkeley DB, Xerces C++ and XQilla have all been built using buildall.sh and installed in the default location, a typical command to compile C++ code that uses Berkeley DB XML is:

g++ -c -Ipath_to_distribution/install/include -c myapp.cpp

If the libraries are in different locations, such as Xerces and XQilla in /usr/local, Berkeley DB in /usr/local/BerkeleyDB.6.1, and Berkeley DB XML in /usr/local/BerkeleyDBXML.6.0, a command might be:

g++ -c -I/usr/local/include
  -I/usr/local/BerkeleyDBXML.6.1/include
  -I/usr/local/BerkeleyDB.6.0/include -c myapp.cpp

Then, corresponding link commands are:

g++ -o myapp myapp.o -Lpath_to_distribution/install/lib
  -lxqilla -lxerces-c -ldbxml-6.0 -ldb-6.1

and

g++ -o myapp myapp.o -L/usr/local/lib
  -L/usr/local/BerkeleyDBXML.6.0/lib
  -L/usr/local/BerkeleyDB.6.1/lib -lxqilla
  -l xerces-c -ldbxml-6.0 -ldb-6.1

Building Java Applications

Java applications compile normally using javac and require both db.jar and dbxml.jar in their CLASSPATH. Assuming buildall.sh and default installation directories were used these reside in the directory p2d/install/lib. This is a reasonable javac line:

javac -cp"p2d/install/lib/db.jar:p2d/install/lib/dbxml.jar" \
MyClass.java 

where p2d is the path to your distribution.

In order to run the resulting program both CLASSPATH and LD_LIBRARY_PATH (or equivalent) must be set properly. For example:

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:p2d/install/lib
export CLASSPATH=$CLASSPATH:\
p2d/install/lib/db.jar:p2d/install/lib/dbxml.jar
java MyClass