Currently MySQL connector/c++ binary version of the highest only support vs2008,vs2015 need to download source code self-compiled.
1.CMAKE
Download the latest stable version on the website
Add the Bin directory to the environment variable path
2.Boost
Also to the official website to download the latest stable version, you can download the compiled version.
3.MySQL Client Library
MySQL Client library header file in the MySQL directory in the Include directory, you can download the MySQL Windows version of the ZIP installation package, only unzip does not install.
4. Download MySQL connector/c++ source code
http://dev.mysql.com/downloads/connector/cpp/
Select "Source Code" in "Select Platform" to download the extract
5. Build vs Solution file
(1)x64
Open a CMD window (admin privileges) and go to the extracted MySQL connector root directory
Perform
Cmake-g "Visual Studio Win64"-dboost_root:string=boost_x64_dir-dmysql_dir:string=mysql_x64_dir
which
- Win64 is very important, otherwise the x86 solution is generated.
- -dboost_root:string declares the root directory of the Boost library,-dmysql_dir:string declares the installation path for MySQL, Boost_x64_dir and Mysql_x64_dir according to their configuration settings.
(2) X32
Open a CMD window (admin privileges) and go to the extracted MySQL connector root directory
Perform
Cmake-g "Visual Studio"-dboost_root:string=boost_x32_dir-dmysql_dir:string=mysql_x32_dir
which
- -dboost_root:string declares the root directory of the Boost library,-dmysql_dir:string declares the installation path for MySQL, Boost_x32_dir and Mysql_x32_dir according to their configuration settings.
6. Compiling MySQL Connector
In the MySQL connector root directory, you can see the generated. sln file, double-click open to see dozens of project files, in addition to the library includes examples, tests, etc.
In the Solution Explorer window, locate the Mysqlcppconn project, right-click, select Build
Failed......
(1) Find the structure Timespec redefine, find the header file My_global.h, add at the beginning
#define Have_struct_timespec
(2) in the "Output" window, select the output source for "generate", Ctrf+f, search "error", you can see
>c:\program Files (x86) \ Windows Kits\10\include\10.0.10150.0\ucrt\stdio.h (1927): Fatal error C1189: #error: Macro Definition of snprintf conflicts with standard Library function declaration
The previous line is
2> d:\bin\mysql-connector-c++-1.1.6\driver\nativeapi/mysql_private_iface.h: NOTE: See the previous definition of "snprintf"
Double-click on this line, navigate to the 48 line of Mysql_private_iface.h, comment out
// #if (defined (_WIN32) | | defined (_WIN64)) &&!defined (snprintf) // #define SNPRINTF _snprintf // #endif
In the Output window, select the output from "Generate", click "Remove all" to generate the project again
(3) failure ... Again, look at the generated information, the same problem
Double-click to navigate to the 516 line of m_config.h, and note the
// #define SNPRINTF _snprintf
7. Attach the x32 version of the connection library after compilation
Baidu Cloud
8. Thanks
Refer to She Xiaojun's CSDN blog, thanks!
vs2015 compiling MySQL C + + connector