Documentation Home
MySQL Connector/ODBC Developer Guide
Related Documentation Download this Manual
PDF (US Ltr) - 1.7Mb
PDF (A4) - 1.7Mb


MySQL Connector/ODBC Developer Guide  /  Connector/ODBC Installation  /  Building Connector/ODBC from a Source Distribution on Windows

4.4 Building Connector/ODBC from a Source Distribution on Windows

You only need to build Connector/ODBC from source on Windows to modify the source or installation location. If you are unsure whether to install from source, please use the binary installation detailed in Section 4.1, “Installing Connector/ODBC on Windows”.

Building Connector/ODBC from source on Windows requires a number of different tools and packages:

  • MDAC, Microsoft Data Access SDK from https://www.microsoft.com/en-in/download/details.aspx?id=21995.

  • A suitable C++ compiler, such as Microsoft Visual C++ or the C++ compiler included with Microsoft Visual Studio 2015 or later. Compiling Connector/ODBC 5.3 can use VS 2013.

  • CMake.

  • The MySQL client library and include files from MySQL 8.0 or higher for Connector/ODBC 9.1, or MySQL 5.7 for Connector/ODBC 5.3. This is required because Connector/ODBC uses calls and structures that do not exist in older versions of the library. To get the client library and include files, visit https://dev.mysql.com/downloads/.

Build Steps

Set the environment variables for the Visual Studio toolchain. Visual Studio includes a batch file to set these for you, and installs a Start menu shortcut that opens a command prompt with these variables set.

Set MYSQL_DIR to the MySQL server installation path, while using the short-style file names. For example:

C:\> set MYSQL_DIR=C:\PROGRA~1\MySQL\MYSQLS~1.0

Build Connector/ODBC using the cmake command-line tool by executing the following from the source root directory (in a command prompt window):

C:\> cmake -G "Visual Studio 12 2013"

This produces a project file that you can open with Visual Studio, or build from the command line with either of the following commands:

C:\> devenv.com MySQL_Connector_ODBC.sln /build Release

While building Connector/ODBC from source, dynamic linking with the MySQL client library is selected by default—that is, the MYSQLCLIENT_STATIC_LINKING cmake option is FALSE by default (however, the binary distributions of Connector/ODBC from Oracle are linked statically to the client library). If you want to link statically to the MySQL client library, set the MYSQLCLIENT_STATIC_LINKING option to TRUE, and use the MYSQLCLIENT_LIB_NAME option to supply the client library's name for static linking:

C:\> cmake -G "Visual Studio 12 2013" -DMYSQLCLIENT_STATIC_LINKING:BOOL=TRUE  \
 DMYSQLCLIENT_LIB_NAME=client_lib_name_with_extension

Also use the MYSQLCLIENT_LIB_NAME option to link dynamically to a MySQL client library other than libmysql.dll. cmake looks for the client library under the location specified by the MYSQL_LIB_DIR option; if the option is not specified, cmake looks under the default locations inside the folder specified by the MYSQL_DIR option.

Since Connector/ODBC 8.0.11, use BUNDLE_DEPENDENCIES to install external library runtime dependencies, such as OpenSSL, together with the connector. For dependencies inherited from the MySQL client library, this only works if these dependencies are bundled with the client library itself.

INFO_SRC: this file provides information about the product version and the source repository from which the distribution was produced. Was added in Connector/ODBC 8.0.14.

Optionally link Connector/ODBC statically (equivalent to the /MT compiler option in Visual Studio) or dynamically (equivalent to the /MD compiler option in Visual Studio) to the Visual C++ runtime. The default option is to link dynamically; if you want to link statically, set the option STATIC_MSVCRT:BOOL=TRUE, that is:

C:\> cmake -G "Visual Studio 12 2013" -DSTATIC_MSVCRT:BOOL=TRUE

The STATIC_MSVCRT option and the MYSQLCLIENT_STATIC_LINKING option are independent of each other; that is, you can link Connector/ODBC dynamically to the Visual C++ runtime while linking statically to the MySQL client library, and vice versa. However, if you link Connector/ODBC dynamically to the Visual C++ runtime, you also need to link to a MySQL client library that is itself linked dynamically to the Visual C++ runtime; and similarly, linking Connector/ODBC statically to the Visual C++ runtime requires linking to a MySQL client library that is itself linked statically to the Visual C++ runtime.

To compile a debug build, set the cmake build type so that the correct versions of the MySQL client libraries are used; also, because the MySQL C client library built by Oracle is not built with the debug options, when linking to it while building Connector/ODBC in debug mode, use the WITH_NODEFAULTLIB option to tell cmake to ignore the default non-debug C++ runtime:

C:\> cmake -G "Visual Studio 14 2015" -DWITH_DEBUG=1  -DWITH_NODEFAULTLIB=libcmt

Create the debug build then with this command:

C:\> devenv.com MySQL_Connector_ODBC.sln /build Debug

Upon completion, the executables are in the bin/ and lib/ subdirectories.

See Section 4.1.1, “Installing the Windows Connector/ODBC Driver Using the Zipped DLL Package” on how to complete the installation by copying the binary files to the right locations and registering Connector/ODBC with the ODBC manager.