3.5. Adding libdbi to your project

If your project uses autoconf to manage the build process on the target machine, you should add some tests to your ./configure script to check for the presence and usability of libdbi. The following example shows how this can be done:

dnl check for dynamic linking functions
AC_CHECK_LIB(dl,dlopen)

dnl check for the libdbi library
AC_CHECK_LIB(dbi,dbi_initialize)

dnl to check for the availability and function of a particular
dnl driver we need a runtime check (since the driver is loaded
dnl dynamically). This example checks for the mysql driver
AC_MSG_CHECKING("for libdbi mysql driver (dynamic load)")
AC_RUN_IFELSE(
  [AC_LANG_PROGRAM(,
    [[dbi_initialize(0); return(dbi_conn_new("mysql") ? 0 : 1);]])],
  [AC_MSG_RESULT("yes")],
  [AC_MSG_FAILURE("mysql driver not installed?")])

The first two tests add the appropriate flags to the LIBS variable to link against the required libraries.

In addition, you have to make sure that both the directory which contains the libdbi header file directory (usually /usr/include or /usr/local/include) as well as the directory which contains the libdbi library (usually /usr/lib or /usr/local/lib) are accessible to the compiler and to the linker by using the -I and -L compiler flags, respectively.