使用Visual Studio 2015 Win64编译MySQL连接器
Compiling MySQL Connector with Visual Studio 2015 Win64
在用cmake创建了一个解决方案后,我在构建过程中在Visual Studio中遇到了1400个错误。主要的问题是,似乎没有人编译连接器,只是将预编译的库用于他们的项目,在Windows上更是如此。以下是一些错误,timespec似乎又被重新定义了一次,首先是在中,然后是在my_global.h中的第二次,错误和定义如下。
所以问题是,我到底该如何修复1400个错误?
或者至少,一些关于如何摆脱重新定义的建议会很棒!
time.h#ifndef _CRT_NO_TIME_T结构时间规范{time_t tv_sec;//秒->=0长tv_nsec;//纳秒-[0999999999]};#endifmy_global.h
struct timespec {
union ft64 tv;
/* The max timeout value in millisecond for native_cond_timedwait */
long max_timeout_msec;
};
错误C2011"timespec":"struct"类型重新定义(编译源文件C:\Users\DDubini\Downloads\mysql-connector-c6.1.6-src\myys\my_mess.C)mysys C:\Users\ddubini\Downloads\myql-connector-C 6.1.6-src=include\my_global.h 660
错误C2039"tv":不是"timespec"的成员(编译源文件C:\Users\DDubini\Downloads\mysql-connector-c6.1.6-src\myys\my_malloc.C)mysys C:\Users\ddubini\Downloads\mysql-connectorc-6.1.6-src=include\my_global.h 681
"->tv"左侧的错误C2227必须指向class/struct/union/generic类型(编译源文件C:\Users\DDubinin\Downloads\mysql-connector-c6.1.6-src\libmysql\authentication_win\handshake.cc)auth_win_client C:\Users\DDubinin\Downloads\mysql-connectorc-6.1.6-src=include\my_global.h 681
"->max_timeout_msec"左侧的错误C2227必须指向class/struct/union/generic类型(编译源文件C:\Users\DDubinion\Downloads\mysql-connector-c6.1.6-src\libmysql\authentication_win\plugin_client.cc)auth_win_client C:\Users\ddubinion\\Downloads\mysql-conconnector-c6.1.6-src\include\my_global.h 682
我将关闭此问题,设法使用较旧的VS2013 x64 Visual Studio版本和CMake 4.3.1…编译源代码
Visual Studio 2015中的新变化似乎正在破坏C连接器的源代码,我希望MySQL团队能在未来的版本中解决这个问题。
我使用了mysql服务器代码(即mysql-5.7.13.zip),并从中编译了mysql连接器/C。
促使我在vs 2015中编译此代码的原因是,当我编译mysqlcppconne 1.1.8时,我得到了错误:
error LNK2038:mismatch detected for `_MSC_VER`:value '1800' does not match value '1900'
CCD_ 1、CCD_。
MSVC++14.0 _MSC_VER == 1900 (Visual Studio 2015)
MSVC++12.0 _MSC_VER == 1800 (Visual Studio 2013)
MSVC++11.0 _MSC_VER == 1700 (Visual Studio 2012)
MSVC++10.0 _MSC_VER == 1600 (Visual Studio 2010)
MSVC++9.0 _MSC_VER == 1500 (Visual Studio 2008)
MSVC++8.0 _MSC_VER == 1400 (Visual Studio 2005)
MSVC++7.1 _MSC_VER == 1310 (Visual Studio 2003)
MSVC++7.0 _MSC_VER == 1300
MSVC++6.0 _MSC_VER == 1200
MSVC++5.0 _MSC_VER == 1100
我搜索发现,这表明我从mysql下载的mysqlcppconn-static.lib
是使用VS2013编译的,这导致了VS2015中的错误。
我很自然地遵循了这个指南,它对我来说很好
http://nov11.github.io/jekyll/update/2017/04/24/compilemysqlcppconnector1.1.8.html
我的操作系统是windows 10 x86
总结如下:
git克隆mysqlcppconnen源代码并检查所需版本
git clone https://github.com/mysql/mysql-connector-cpp.git git checkout 1.1.8
在本地下载boost和mysql服务器代码,并修改
CMakeLists.txt
,以便编译器可以找到库在这种情况下,我的boost版本是
boost_1_64_0
,mysql是mysql-5.6.26-win32
。可以在此处下载:https://cdn.mysql.com/archives/mysql-5.6/mysql-5.6.26-win32.zip修改
CMakeLists.txt
,添加行:SET(BOOST_ROOT "C:\boost_1_64_0") SET(MYSQL_DIR "C:\mysql-5.6.26-win32") SET(MYSQL_VERSION "5.6.26")
cmake:
mkdir build && cd build cmake -G "Visual Studio 14 2015" -A win32 -DMYSQLCLIENT_STATIC_LINKING=yes ..
求解
snprintf link error
:在mysql服务器中注释掉
1800
0中的define snprintf _snprintf
行,包括代码生成lib文件:
cmake --build <your-build-folder-path> --config Release --target mysqlcppconn -j 4 -- cmake --build <your-build-folder-path> --config Release --target mysqlcppconn-static -j 4 --
- 二叉排序树无法编译
- 致命错误mysql.h:编译期间没有这样的文件或目录
- Mysql++ 简单脚本编译失败
- 在Linux环境下用MYSQL.h编译C++程序
- #include < mysql.h> & #include <my_global.h> 导致编译错误
- 从C++连接MySQL时程序错误中"error: stray ‘302’"编译错误
- 在windows 7 64位中编译Qt 4.8.0的MySQL驱动程序
- 使用Visual Studio 2015 Win64编译MySQL连接器
- 编译MySQL连接器/C++的examples/standalone_example.cpp失败
- Qt编译问题w/ MySQL - Mac OS X
- 使用 MINGW32 在 Debian 上使用 C++ 和 MySQL 进行编译
- 如何定位MySQL头文件来编译qt
- 编译并运行文件夹中提供的MySQL++和C++示例
- 为什么简单的mysql++代码编译独立,而不是在项目
- "cannot create .moc/main.moc "有一个错误,当我编译Qt5.7的mysql驱动程序时
- 编译mysql连接器c++与mingw,编译错误
- Qt-如何获取|编译Mysql驱动程序
- 无法编译mysql源代码
- 使用MySQL支持编译QuickFIX C++
- 在Cygwin中使用MySQL编译c++应用程序