OpenDBX/Setup/Unix-like/Building from source

From Linuxnetworks
< OpenDBX‎ | Setup/Unix-like
Revision as of 22:33, 10 June 2009 by Nose (Talk | contribs)

Jump to: navigation, search
Logo-opendbx.png

Compilation

Basic

Please get the latest version from the download page first.

The compilation itself is a rather easy task. All you need is a standard ANSI C compiler like gcc (tested with 2.95 and above), the make tool and a shell which can execute scripts generated by autoconf/automake.

Calling ./configure in the opendbx directory without arguments only generates Makefiles for the OpenDBX library itself, which isn't useful on its own. You have to tell the script to also create Makefiles for one or more backends. This is done by appending the --with-backends parameter and specifying the backends you want to build:

./configure --with-backends="mysql pgsql sqlite3"

would create Makefiles for the MySQL, PostgreSQL and SQLite3 backends. Possible database identifiers for the --with-backends option are:

  • firebird (Firebird/Interbase)
  • mssql (MS SQL Server)
  • mysql (MySQL server)
  • oracle (Oracle version 8 or higher)
  • pgsql (PostgreSQL)
  • sqlite (SQLite library version 2)
  • sqlite3 (SQLite library version 3)
  • sybase (Sybase ASE)

If the header files are not installed in /usr/include/, you have to give ./configure some hints where to find them:

CPPFLAGS="-I/usr/include/mysql" ./configure --with-backends="mysql"

will additionally look for the MySQL header files in /usr/include/mysql. The same (also in combination with CPPFLAGS) can be used for library paths. Some distributions install the MySQL libraries in /usr/lib/mysql for example:

LDFLAGS="-L/usr/lib/mysql" ./configure --with-backends="mysql"

Calling "./configure --help" tells you what parameters are allowed and how to use them. If something is missing, ./configure will tell you what it is. In the end you have to call "make" in the package directory to actually compile the source code:

tar xfvz opendbx-x.y-z.tar.gz
cd opendbx-x.y.z
./configure --with-backends="mysql"
make

A complete example compiling more than one backend with require both CPPFLAGS and LDFLAGS for non-standard file locations would be:

CPPFLAGS="-I/usr/include/postgresql -I/usr/include/mysql" \
LDFLAGS="-L/usr/lib/postgresql -L/usr/lib/mysql" \
./configure --with-backends="pgsql mysql"

Installation is done by executing "make install" in the package directory. This will copy the libraries to /usr/local/lib and /usr/local/lib/opendbx and the header file to /usr/local/include. Please keep in mind that the files in /usr/local/lib/ are usually not found by the linker if the directory isn't listed in /etc/ld.so.conf.

If you want to install the files somewhere else, for example into the standard locations (/usr/lib, /usr/include and /usr/bin) execute ./configure with --prefix or its related parameters, e.g.

./configure --prefix=/usr --with-backends="sqlite3"

Built-in backends

OpenDBX can also be built as single library with the configured backends included in the main library file. This removes the need for loading backends dynamically but is limited afterwards to the backends already included. To enable this option, you have to add another parameter for the configure script:

./configure --enable-singlelib --with-backends="mysql pgsql sqlite3"

From the applications point of view there's no difference between dynamic loading and using built-in backends.

Without utilities

Beginning with OpenDBX 1.3.11, the applications in the "utils/" directory (namely odbx-sql, the swiss army knife for talking to databases interactively or in batch mode) are build by default. This adds a dependency to the readline library for working on the commandline much more comfortable. If you don't want this applications to be built or don't have the readline library available, you can disable it via the configure script:

./configure --disable-utils --with-backends="firebird"

Linux

The necessary files for certain backends might be available at different locations in some distributions. Below are the ./configure calls for the major distributions if they differ from the default.

Debian/Ubuntu

CPPFLAGS="-I/usr/include/mysql" \
LDFLAGS="-L/usr/lib/mysql" \
./configure --with-backends="mysql"
CPPFLAGS="-I/usr/include/postgresql" \
LDFLAGS="-L/usr/lib/postgresql" \
./configure --with-backends="pgsql"

Fedora/RHEL

CPPFLAGS="-I/usr/include/mysql" \
LDFLAGS="-L/usr/lib/mysql" \
./configure --with-backends="mysql"

Mandriva

CPPFLAGS="-I/usr/include/mysql" \
./configure --with-backends="mysql"
CPPFLAGS="-I/usr/include/pgsql" \
./configure --with-backends="pgsql"

SuSE

CPPFLAGS="-I/usr/include/mysql" \
LDFLAGS="-L/usr/lib/mysql" \
./configure --with-backends="mysql"
CPPFLAGS="-I/usr/include/pgsql" \
./configure --with-backends="pgsql"

Oracle

The location of the Oracle files isn't distribution specific but are placed in an arkward location by Oracle. The necessary preprocessor and library flags are:

CPPFLAGS="-I/usr/lib/oracle/xe/app/oracle/product/<version>/client/rdbms/public" \
LDFLAGS="-L/usr/lib/oracle/xe/app/oracle/product/<version>/client/lib" \
./configure --with-backends="oracle"

Please replace <version> with the version of your installed Oracle package.

Windows

Starting with release 1.3.10, the Windows platform is supported via the Cygwin or MinGW environments.

Since version 1.3.11, the applications in "utils/" directory are built by default. If you want to leave this out of the build process, you can disable compilation.

Cygwin

You need the following packages in order to compile the library:

  • Basic tools
  • GNU make package
  • GCC C/C++ compiler
  • Libraries and header files of the database libraries
  • the readline library and header files (if not disabled)
  • the "file" command

The steps to build the library are the same as in the Unix environment.

MinGW

MinGW is a collection of freely available and freely distributable Windows specific header files and import libraries, augmenting the GNU Compiler Collection, (GCC), and its associated tools, (GNU binutils). MinGW provides a complete Open Source programming tool set which is suitable for the development of native Windows programs that do not depend on any 3rd-party C runtime DLL.

Download the following packages from the MinGW Sourceforge page:

  • Automated MinGW installer
  • MSYS base system (executable of current release)

There are some tutorials available, how to install MinGW:

The steps to build the OpenDBX library are the same as in the Unix environment.

It's hard to build the applications in the "utils/" directory because of the dependencies. The easiest way is to disable building the utilities. Alternatively, you can try installing the required header and library files (complete sources) for Windows:

By default, the packages are installed in "C:\Program Files\GnuWin32", so you have to add the "include/" and "lib/" directory to ./configure:

CPPFLAGS="-I/c/Progra~1/GnuWin32/include" \
LDFLAGS="-L/c/Progra~1/GnuWin32/lib" \
./configure --with-backends="sqlite3"

Please note that it seems not be possible to use "Program Files" instead of "Progra~1" as this leads to a weird error message that the C compiler cannot create executables.

All backends could be build invoking ./configure like shown below. Please keep in mind that the paths may differ depending on the location of the installed packages:

CPPFLAGS=" \
 -I/c/Progra~1/MySQL/MySQLS~1.0/include/ \
 -I/c/Progra~1/PostgreSQL/8.3/include/ \
 -I/c/Progra~1/Firebird/Firebird_2_1/include/ \
 -I/c/Progra~1/sybase/OCS-15_0/include/ \
 -I/c/Progra~1/Oracle/product/11.1.0/instantclient_11_1/sdk/include \
 -I/c/Progra~1/GnuWin32/include \
" \
LDFLAGS=" \
 -L/c/Progra~1/MySQL/MySQLS~1.0/bin \
 -L/c/Progra~1/MySQL/MySQLS~1.0/lib/opt \
 -L/c/Progra~1/PostgreSQL/8.3/bin \
 -L/c/Progra~1/Firebird/Firebird_2_1/lib \
 -L/c/Progra~1/Firebird/Firebird_2_1/bin \
 -L/c/Progra~1/sybase/OCS-15_0/dll \
 -L/c/Progra~1/Oracle/product/11.1.0/instantclient_11_1 \
 -L/c/Progra~1/GnuWin32/lib \
" \
./configure --with-backends="mssql mysql odbc oracle pgsql sqlite3 sybase"