4.3 Dynamically Linking Connector/C++ Against the MySQL Client Library


This section refers to dynamic linking of Connector/C++ with the client library, not dynamic linking of the application to Connector/C++.

Precompiled binaries of Connector/C++ use static binding with the client library by default.

An application that uses Connector/C++ can be either statically or dynamically linked to the Connector/C++ libraries. Connector/C++ is usually statically linked to the underlying MySQL client library (or Connector/C). Note that, unless otherwise stated, reference to the MySQL client library is also taken to include Connector/C, which is a separately packaged, standalone version of the MySQL client library. From Connector/C++ 1.1.0 on, it is possible to also dynamically link to the underlying MySQL client library. The ability of Connector/C++ to dynamically link to MySQL client library is not enabled by default. Enabling this feature is done through a compile-time option when compiling the Connector/C++ source code.

To use the ability to dynamically link the client library to Connector/C++, define the MYSQLCLIENT_STATIC_BINDING:BOOL when building the Connector/C++ source code:

shell> rm CMakeCache.txt
shell> make clean
shell> make
shell> make install

Now, in your application, when creating a connection, Connector/C++ will select and load a client library at runtime. It will choose the client library by searching defined locations and environment variables depending on the host operating system. It is also possible when creating a connection in an application to define an absolute path to the client library to be loaded at runtime. This can be convenient if you have defined a standard location from which you want the client library to be loaded. This is sometimes done to circumvent possible conflicts with other versions of the client library that may be located on the system.