MySQL Connector/C Developer Guide  /  ...  /  Installing Connector/C from Source on Microsoft Windows

4.2.2 Installing Connector/C from Source on Microsoft Windows

To build Connector/C on Microsoft Windows, Visual Studio 8 or 9 is recommended. The Express Edition of Visual Studio and other compilers might work, but are untested.

You also need CMake 2.6 or newer, which is available from

To build and install the source distribution, use the following procedure:

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

  2. Change location to the top-level directory of the source distribution.

  3. Generate the Makefile by entering the following command in a command-prompt window:

    shell> cmake -G "Visual Studio 9 2008"

    For other CMake options that you might find useful, see Other Connector/C Build Options.

    The result of the cmake command is a project (solution) file, libmysql.sln, that you can open with Visual Studio. Alternatively, build from the command line with either of these commands:

    shell> libmysql.sln /build Release
    shell> libmysql.sln /build RelWithDebInfo

    For other versions of Visual Studio or for an nmake-based build, use the following command to check which generators can be specified with the -G option:

    shell> cmake --help

    To compile a Debug build, you must set the CMake build type so the correct external library versions are used, then compile using the Debug solution configuration:

    shell> cmake -G "Visual Studio 9 2008" -DCMAKE_BUILD_TYPE=Debug
    shell> libmysql.sln /build Debug

    A normal build builds the C API libraries for the lib directory. A Debug build additionally builds debug libraries for the lib/debug directory. You must use the debug libraries to compile clients built using the debug C runtime.

  4. Use the install operation provided by your development environment to install the Connector/C headers, libraries, and utilities. You can also use this CMake command:

    shell> cmake --build . --target INSTALL --config RelWithDebInfo

User Comments
User comments in this section are, as the name implies, provided by MySQL users. The MySQL documentation team is not responsible for, nor do they endorse, any of the information provided here.
  Posted by Thomas Pollak on May 16, 2017
These are the steps for a (Visual Studio 2015) Win64 build:

1) Open CMakeCCompiler.cmake and CMakeCXXCompiler.cmake (generated files) and replace 'set(CMAKE_CXX_SIZEOF_DATA_PTR "4")' with 'set(CMAKE_CXX_SIZEOF_DATA_PTR "${SIZEOF_VOIDP}")'
2) Open Windows.cmake and add replace the foreach loop under the coimment '# Fix CMake's predefined huge stack size' with the following:
STRING(REPLACE "/machine:X86" "/machine:X64" CMAKE_${type}_LINKER_FLAGS "${CMAKE_${type}_LINKER_FLAGS}")
STRING(REPLACE "/machine:X86" "/machine:X64" CMAKE_${type}_LINKER_FLAGS_INIT "${CMAKE_${type}_LINKER_FLAGS_INIT}")
3) Now generate the VS solution with 'cmake -DSIZEOF_VOIDP=8 -G "Visual Studio 14 2015 Win64"' to generate the project, optionally you maybe want to add -DWINDOWS_RUNTIME_MD=true to use the DLL runtime or -DCMAKE_BUILD=Debug for Debug
4) build with 'cmake --build .', the install step failed for some reason in the X64 configuration but I just copied over the libs since I didn't want to bother with fixing the isntall script as well.

I couldn't find a source repository for the Connector/C... @MySQL: How about moving that to github, so that people can fix issues?
Sign Up Login You must be logged in to post a comment.