MySQL Connector/C++ Developer Guide  /  Building Connector/C++ Applications  /  Building Connector/C++ Applications on Windows with Microsoft Visual Studio

## 5.3 Building Connector/C++ Applications on Windows with Microsoft Visual Studio

This section describes how to build Connector/C++ applications for Windows using Microsoft Visual Studio. For general application-building information, see Section 5.1, “Building Connector/C++ Applications: General Considerations”.

Developers using Microsoft Windows must satisfy the following requirements:

• Microsoft Visual Studio 2015 is required to build Connector/C++ applications.

• Your applications should use the same linker configuration as Connector/C++. For example, use one of /MD, /MDd, /MT, or /MTd.

Connector/C++ is available as a dynamic or static library to use with your application. This section describes how to link the library to your application.

To use a dynamic library file (.dll extension), link your application with a .lib import library. At runtime, the application must have access to the .dll library.

The following table indicates which import library and dynamic library files to use for Connector/C++. LIB denotes the Connector/C++ installation library path name. the name of the last path component differs depending on whether you use a 64-bit or 32-bit package. The name ends with lib64/vs14 for 64-bit packages, lib/vs14 for 32-bit packages. In addition, import library files are found in a subdirectory named for the build type used to build the libraries, here designated as vs14.

Table 5.1 Connector/C++ Import Library and Dynamic Library Names

Connector Type Import Library Dynamic Library
X DevAPI, X DevAPI for C LIB/vs14/mysqlcppconn8.lib LIB/mysqlcppconn8-1-vs14.dll
JDBC LIB/vs14/mysqlcppconn.lib LIB/mysqlcppconn-7-vs14.dll

To use a static library file (.lib extension), link your application with the library.

The following table indicates which static library files to use for Connector/C++. LIB denotes the Connector/C++ installation library path name. The name of the last path component differs depending on whether you use a 64-bit or 32-bit package. The name ends with lib64 for 64-bit packages, lib for 32-bit packages. In addition, static library files are found in a subdirectory named for the build type used to build the libraries, here designated as vs14.

Table 5.2 Connector/C++ Static Library Names

Connector Type Static Library
X DevAPI, X DevAPI for C LIB/vs14/mysqlcppconn8-static.lib
JDBC LIB/vs14/mysqlcppconn-static.lib

### Building Connector/C++ Applications with Microsoft Visual Studio

The initial steps for building an application to use either the dynamic or static library are the same. Some additional steps vary, depend on whether you are building your application to use the dynamic or static library.

1. Start a new Visual C++ project in Visual Studio.

2. In the drop-down list for build configuration on the toolbar, change the configuration from the default option of Debug to Release.

Connector/C++ and Application Build Configuration Must Match

Because the application build configuration must match that of the Connector/C++ it uses, Release is required when using an Oracle-built Connector/C++, which is built in the release configuration. When linking dynamically, it is possible to build your code in debug mode even if the connector libraries are built in release mode. However, in that case, it will not be possible to step inside connector code during a debug session. To be able to do that, or to build in debug mode while linking statically to the connector, you must build Connector/C++ from source yourself using the Debug configuration.

3. From the main menu select Project, Properties. This can also be accessed using the hot key + .

4. Under Configuration Properties, open the tree view.

5. Select C/C++, General in the tree view.

6. In the Additional Include Directories text field, add the include/ directory of Connector/C++ (it should be located within the Connector/C++ installation directory). Also add the Boost library's root directory, if Boost is required to build the application (see Section 5.1, “Building Connector/C++ Applications: General Considerations”).

8. In the Additional Library Directories text field, add the Connector/C++ library directory (it should be located within the Connector/C++ installation directory). The library directory name ends with lib64 (for 64-bit builds) or lib (for 32-bit builds).

The remaining steps depend on whether you are building an application to use the Connector/C++ dynamic or static library.

### Dynamic Build

If you are building an application to use the Connector/C++ dynamic library, follow these steps:

1. Open Linker, Input in the Property Pages dialog.

2. Add the appropriate import library name into the Additional Dependencies text field (see Linking Connector/C++ to Applications).

3. Choose the C++ Runtime Library to link to. In the Property Pages dialog, open C++, Code Generation in the tree view, and then select the appropriate option for Runtime Library.

Link to the dynamic version of the C++ Runtime Library by selecting the /MD compiler option. Also, target hosts running the client application must have the Visual C++ Redistributable for Visual Studio installed. The required version is VC++ Redistributable 2015.

Do not use the /MTd or /MDd option if you are using an Oracle-built Connector/C++. For an explanation, see this discussion: Connector/C++ and Application Build Configuration Must Match.

4. Copy the appropriate dynamic library to the same directory as the application executable (see Linking Connector/C++ to Applications). Alternatively, extend the PATH environment variable using SET PATH=%PATH%;C:\path\to\cpp, or copy the dynamic library to the Windows installation directory, typically C:\windows.

The dynamic library must be in the same directory as the application executable, or somewhere on the system's path, so that the application can access the Connector/C++ dynamic library at runtime.

### Static Build

If you are building your application to use the static library, follow these steps:

1. Open Linker, Input in the Property Pages dialog.

2. Add the appropriate static library name into the Additional Dependencies text field (see Linking Connector/C++ to Applications).

3. To compile code that is linked statically with the connector library, define a macro that adjusts API declarations in the header files for usage with the static library. By default, the macro is defined to declare functions to be compatible with an application that calls a DLL.

In the Project, Properties tree view, under C++, Preprocessor, enter the appropriate macro into the Preprocessor Definitions text field:

• For Connector/C++ applications that use X DevAPI or X DevAPI for C, define the STATIC_CONCPP macro. All that matters is that you define it; the value does not matter.

• For Connector/C++ applications that use the legacy JDBC API, define the CPPCONN_PUBLIC_FUNC macro as an empty string. To ensure this, define the macro as CPPCONN_PUBLIC_FUNC=, not as CPPCONN_PUBLIC_FUNC.

4. Choose the C++ Runtime Library to link to. In the Property Pages dialog, open C++, Code Generation in the tree view, and then select the appropriate option for Runtime Library.

Link to the dynamic version of the C++ Runtime Library by selecting the /MD compiler option. Also, target hosts running the client application must have the Visual C++ Redistributable for Visual Studio installed. The required version is VC++ Redistributable 2015.

Do not use the /MTd or /MDd option if you are using an Oracle-built Connector/C++. For an explanation, see this discussion: Connector/C++ and Application Build Configuration Must Match.