CppDB
Linking Existing Drivers Statically

Before You Begin

In some cases you want to have drivers statically linked into your application. The simplest way is to build it with internal option for specific backend you need. This is the best and less error prone way.

However you may also to use it directly without rebuilding cppdb library.

Linking the Module

CppDB comes with following libraries (the names below are for Linux, under other OS they may be slightly different):

By default, cppdb tries to load the module's shared object on the run time. However, if you want to link the module statically into the library you may do following.

  1. During linking use static library for the cppdb and for the module you need.
  2. Link with the appropriate native client library for the module.

For example:

g++ my_program.o /usr/lib/libcppdb.a /usr/lib/libcppdb_sqlite3.a -lpthread -ldl -lsqlite3

Where libcppdb.a and libcppdb_sqlite3.a are the static version of the library and the module, "-lpthread -ldl" are dependencies of libcppdb and "-lsqlite3" is the dependency of sqlite3 module.

Adding Backend to Driver

Linking only with the backend is not enough, you need also install the driver to cppdb::driver_manager so it would know to use it directly rather then try to load it dynamically.

Every backend as a single entry point called "cppdb_XXX_get_connection" where XXX is the backend name, so together with cppdb::backend::static_driver you can install it to the cppdb::driver_manager driver_manger as shown in the example below:

extern "C" {
        cppdb::backend::connection *cppdb_sqlite3_get_connection(cppdb::connection_info const &);
}
void add_driver()
{
  cppdb::driver_manager::instance().install_driver("sqlite3",new cppdb::backend::static_driver(cppdb_sqlite3_get_connection));
}
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator