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:

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
C:\> devenv.com MySQL_Connector_ODBC.sln /build RelWithDebInfo

By default, Connector/ODBC is linked statically with the MySQL client library mysqlclient.lib. If you want to link dynamically or to another MySQL client library, use the MYSQLCLIENT_LIB_NAME option to supply the client library's name:

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

To compile a debug build, set the cmake build type so that the correct versions of the MySQL client libraries are used:

C:\> cmake -G "Visual Studio 12 2013" -DWITH_DEBUG=1
C:\> devenv.com MySQL_Connector_ODBC.sln /build Debug
Note

You cannot build Connector/ODBC in debug mode and link it to the static C client library built by Oracle, which is not built with the debug options; instead, you will have to build the static client library from source with the debug options by using the same version of Visual Studio with which you compile Connector/ODBC.

For Connector/ODBC 5.3.9 and later: You can 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

By default, 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. If you want to use mixed link types, you have to use the WITH_NODEFAULTLIB=vc_runtime_lib_name option to specify the Visual C++ runtime you want to link to; for example:

cmake -G "Visual Studio 12 2013" -DMYSQLCLIENT_STATIC_LINKING:BOOL=FALSE 
  -DSTATIC_MSVCRT:BOOL=TRUE -DWITH_NODEFAULTLIB=msvcrt

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

See Section 4.1.2, “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.