AFAICT是MySQL为Windows提供的唯一预构建的Connector/C++ library是使用Visual Studio 2010构建的。我使用的是Visual Studio 2013,因此我需要从源代码构建。我想使用静态库。
以下是我采取的步骤的粗略描述。我能够构建库(mysqlcppconn-static.lib
),我可以将它添加为依赖项,并将#include
标题添加到我的项目中。但是一旦我尝试实际使用该库,我就会收到大量的链接器错误。
我玩过项目属性,但我仍然卡住了。我怎样才能让它发挥作用?
使用cmake
for Windows,使用-DMYSQLCLIENT_STATIC_LINKING=true
和-G "Visual Studio 12 2013"
选项创建项目和解决方案文件。包含-D
参数以及boost和预构建mysql-connector-c-6.1.6-win32
的路径。
在Visual Studio中打开MYSQLCPPCONN.sln,并构建mysqlcppconn-static项目。
创建一个新的VS解决方案和控制台应用程序项目,我将在其中使用Connector / C ++。
提取预构建的Connector / C ++库.zip文件,将mysqlcppconn-static.lib
替换为我构建的(Debug& Release),并相应地设置路径。
配置属性 - > C / C ++ - >预处理器 - >预处理器定义:添加CPPCONN_PUBLIC_FUNC=
。
error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '0' doesn't match value '2'
error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MDd_DynamicDebug'
warning LNK4049: locally defined symbol _memmove (et al) imported
warning LNK4217: locally defined symbol _memmove imported in function...
error LNK2001: unresolved external symbol __imp___CrtDbgReportW (et al)
我一直在使用mysqlcppconn-static
中的项目属性,在我使用该库的项目中,试图让它们匹配,但这些错误仍然存在。
以下是一些在两个项目中设置相同的可能相关的项目属性:
Configuration Properties --> C/C++ --> Code Generation
--> Basic Runtime Checks
Debug - /RTC1
Release - Default
--> Runtime Library
Debug - Multi-threaded Debug DLL (/MDd)
Release - Multi-threaded DLL (/MD)
在我的项目(使用连接器)中,我有这个链接器属性:
Configuration Properties --> Linker --> Input --> Ignore Specific Default Libraries
Debug - MSVCRTD.lib
Release - MSVCRT.lib
1>mysqlcppconn-static.lib(net_serv.obj) : error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '0' doesn't match value '2' in useMySQLConnectorCpp.obj
1>mysqlcppconn-static.lib(net_serv.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MDd_DynamicDebug' in useMySQLConnectorCpp.obj
1>mysqlcppconn-static.lib(plugin_client.obj) : error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '0' doesn't match value '2' in useMySQLConnectorCpp.obj
1>mysqlcppconn-static.lib(plugin_client.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MDd_DynamicDebug' in useMySQLConnectorCpp.obj
[snip]
1>mysqlcppconn-static.lib(mysql_native_statement_wrapper.obj) : warning LNK4049: locally defined symbol _memmove imported
1>mysqlcppconn-static.lib(mysql_art_rset_metadata.obj) : warning LNK4049: locally defined symbol _memmove imported
[snip]
1>mysqlcppconn-static.lib(mysql_native_connection_wrapper.obj) : warning LNK4217: locally defined symbol _memmove imported in function "public: __thiscall std::_String_alloc<0,struct std::_String_base_types<char,class std::allocator<char> > >::~_String_alloc<0,struct std::_String_base_types<char,class std::allocator<char> > >(void)" (??1?$_String_alloc@$0A@U?$_String_base_types@DV?$allocator@D@std@@@std@@@std@@QAE@XZ)
1>mysqlcppconn-static.lib(mysql_art_resultset.obj) : warning LNK4049: locally defined symbol _memmove imported
[snip]
1>mysqlcppconn-static.lib(mysql_client_api.obj) : warning LNK4049: locally defined symbol _memmove imported
1>mysqlcppconn-static.lib(mysql_uri.obj) : warning LNK4217: locally defined symbol _memmove imported in function "public: void __thiscall std::_Wrap_alloc<class std::allocator<char> >::deallocate(char *,unsigned int)" (?deallocate@?$_Wrap_alloc@V?$allocator@D@std@@@std@@QAEXPADI@Z)
1>mysqlcppconn-static.lib(mysql_metadata.obj) : warning LNK4217: locally defined symbol _memmove imported in function __catch$?getProcedures@MySQL_ConnectionMetaData@mysql@sql@@UAEPAVResultSet@3@ABVSQLString@3@00@Z$0
1>mysqlcppconn-static.lib(mysql_warning.obj) : warning LNK4049: locally defined symbol _memmove imported
1>mysqlcppconn-static.lib(mysql_prepared_statement.obj) : warning LNK4049: locally defined symbol _memmove imported
1>useMySQLConnectorCpp.obj : warning LNK4217: locally defined symbol _memmove imported in function "public: static char * __cdecl std::char_traits<char>::move(char *,char const *,unsigned int)" (?move@?$char_traits@D@std@@SAPADPADPBDI@Z)
[snip]
1>mysqlcppconn-static.lib(mysql_native_driver_wrapper.obj) : warning LNK4049: locally defined symbol _memmove imported
1>mysqlcppconn-static.lib(mysql_native_statement_wrapper.obj) : warning LNK4049: locally defined symbol __hypot imported
1>mysqlcppconn-static.lib(mysql_art_rset_metadata.obj) : warning LNK4217: locally defined symbol __hypot imported in function "public: void __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::_Copy(unsigned int,unsigned int)" (?_Copy@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAEXII@Z)
1>mysqlcppconn-static.lib(mysql_resultset_metadata.obj) : warning LNK4049: locally defined symbol __hypot imported
[snip]
1>mysqlcppconn-static.lib(mysql_native_resultset_wrapper.obj) : warning LNK4049: locally defined symbol __hypot imported
1>mysqlcppconn-static.lib(mysql_native_connection_wrapper.obj) : warning LNK4217: locally defined symbol __hypot imported in function "public: __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (??0?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@ABV01@@Z)
1>mysqlcppconn-static.lib(mysql_art_resultset.obj) : warning LNK4049: locally defined symbol __hypot imported
[snip]
1>mysqlcppconn-static.lib(mysql_client_api.obj) : warning LNK4049: locally defined symbol __hypot imported
1>mysqlcppconn-static.lib(mysql_uri.obj) : warning LNK4217: locally defined symbol __hypot imported in function "public: char * __thiscall std::_Wrap_alloc<class std::allocator<char> >::allocate(unsigned int)" (?allocate@?$_Wrap_alloc@V?$allocator@D@std@@@std@@QAEPADI@Z)
1>mysqlcppconn-static.lib(mysql_metadata.obj) : warning LNK4217: locally defined symbol __hypot imported in function __catch$?getUniqueNonNullableKeys@MySQL_ConnectionMetaData@mysql@sql@@QAEPAVResultSet@3@ABVSQLString@3@00@Z$0
1>mysqlcppconn-static.lib(mysql_warning.obj) : warning LNK4049: locally defined symbol __hypot imported
1>mysqlcppconn-static.lib(mysql_prepared_statement.obj) : warning LNK4049: locally defined symbol __hypot imported
1>useMySQLConnectorCpp.obj : warning LNK4217: locally defined symbol __hypot imported in function _hypot
1>mysqlcppconn-static.lib(mysql_driver.obj) : warning LNK4049: locally defined symbol __hypot imported
1>mysqlcppconn-static.lib(mysql_connection.obj) : warning LNK4049: locally defined symbol __hypot imported
1>mysqlcppconn-static.lib(mysql_native_driver_wrapper.obj) : warning LNK4049: locally defined symbol __hypot imported
1>mysqlcppconn-static.lib(mysql_client_api.obj) : warning LNK4217: locally defined symbol __invalid_parameter imported in function "public: void __thiscall std::_Tree_alloc<0,struct std::_Tree_base_types<struct std::pair<class sql::SQLString const ,class boost::shared_ptr<class sql::mysql::NativeAPI::IMySQLCAPI> >,class std::allocator<struct std::pair<class sql::SQLString const ,class boost::shared_ptr<class sql::mysql::NativeAPI::IMySQLCAPI> > > > >::_Free_proxy(void)" (?_Free_proxy@?$_Tree_alloc@$0A@U?$_Tree_base_types@U?$pair@$$CBVSQLString@sql@@V?$shared_ptr@VIMySQLCAPI@NativeAPI@mysql@sql@@@boost@@@std@@V?$allocator@U?$pair@$$CBVSQLString@sql@@V?$shared_ptr@VIMySQLCAPI@NativeAPI@mysql@sql@@@boost@@@std@@@2@@std@@@std@@QAEXXZ)
1>mysqlcppconn-static.lib(mysql_art_resultset.obj) : warning LNK4049: locally defined symbol __invalid_parameter imported
1>mysqlcppconn-static.lib(mysql_ps_resultset.obj) : warning LNK4049: locally defined symbol __invalid_parameter imported
1>mysqlcppconn-static.lib(mysql_resultset.obj) : warning LNK4049: locally defined symbol __invalid_parameter imported
1>mysqlcppconn-static.lib(mysql_driver.obj) : warning LNK4217: locally defined symbol __invalid_parameter imported in function "public: bool __thiscall std::_Tree_const_iterator<class std::_Tree_val<struct std::_Tree_simple_types<struct std::pair<class sql::SQLString const ,class boost::shared_ptr<class sql::mysql::MySQL_Driver> > > > >::operator==(class std::_Tree_const_iterator<class std::_Tree_val<struct std::_Tree_simple_types<struct std::pair<class sql::SQLString const ,class boost::shared_ptr<class sql::mysql::MySQL_Driver> > > > > const &)const " (??8?$_Tree_const_iterator@V?$_Tree_val@U?$_Tree_simple_types@U?$pair@$$CBVSQLString@sql@@V?$shared_ptr@VMySQL_Driver@mysql@sql@@@boost@@@std@@@std@@@std@@@std@@QBE_NABV01@@Z)
1>mysqlcppconn-static.lib(mysql_connection.obj) : warning LNK4049: locally defined symbol __invalid_parameter imported
1>mysqlcppconn-static.lib(mysql_metadata.obj) : warning LNK4049: locally defined symbol __invalid_parameter imported
1>mysqlcppconn-static.lib(mysql_prepared_statement.obj) : warning LNK4049: locally defined symbol __invalid_parameter imported
1>mysqlcppconn-static.lib(mysql_resultbind.obj) : warning LNK4049: locally defined symbol ??0exception@std@@QAE@ABQBD@Z (public: __thiscall std::exception::exception(char const * const &)) imported
1>mysqlcppconn-static.lib(mysql_resultset.obj) : warning LNK4049: locally defined symbol ??0exception@std@@QAE@ABQBD@Z (public: __thiscall std::exception::exception(char const * const &)) imported
[snip]
1>mysqlcppconn-static.lib(mysql_resultbind.obj) : warning LNK4049: locally defined symbol ??0exception@std@@QAE@ABV01@@Z (public: __thiscall std::exception::exception(class std::exception const &)) imported
[snip]
1>mysqlcppconn-static.lib(mysql_resultbind.obj) : warning LNK4049: locally defined symbol ??1exception@std@@UAE@XZ (public: virtual __thiscall std::exception::~exception(void)) imported
1>mysqlcppconn-static.lib(mysql_resultset.obj) : warning LNK4049: locally defined symbol ??1exception@std@@UAE@XZ (public: virtual __thiscall std::exception::~exception(void)) imported
[snip]
1>mysqlcppconn-static.lib(mysql_connection.obj) : warning LNK4217: locally defined symbol __strnicmp imported in function __catch$?prepareStatement@MySQL_Connection@mysql@sql@@UAEPAVPreparedStatement@3@ABVSQLString@3@@Z$0
1>mysqlcppconn-static.lib(mysql_connection.obj) : warning LNK4217: locally defined symbol ?name@type_info@@QBEPBDPAU__type_info_node@@@Z (public: char const * __thiscall type_info::name(struct __type_info_node *)const ) imported in function "public: int * __thiscall sql::BaseVariantImpl::get<int>(void)const " (??$get@H@BaseVariantImpl@sql@@QBEPAHXZ)
1>mysqlcppconn-static.lib(mysql_uri.obj) : warning LNK4217: locally defined symbol _atoi imported in function "bool __cdecl sql::mysql::parseUri(class sql::SQLString const &,class sql::mysql::MySQL_Uri &)" (?parseUri@mysql@sql@@YA_NABVSQLString@2@AAVMySQL_Uri@12@@Z)
1>mysqlcppconn-static.lib(mysql_metadata.obj) : warning LNK4217: locally defined symbol _atoi imported in function __catch$?getColumnPrivileges@MySQL_ConnectionMetaData@mysql@sql@@UAEPAVResultSet@3@ABVSQLString@3@000@Z$0
1>mysqlcppconn-static.lib(mysql_metadata.obj) : warning LNK4217: locally defined symbol __snprintf imported in function __catch$?getImportedKeys@MySQL_ConnectionMetaData@mysql@sql@@UAEPAVResultSet@3@ABVSQLString@3@00@Z$0
1>mysqlcppconn-static.lib(mysql_art_resultset.obj) : warning LNK4049: locally defined symbol __snprintf imported
[snip]
1>mysqlcppconn-static.lib(mysql_metadata.obj) : warning LNK4217: locally defined symbol _tolower imported in function "public: int __thiscall sql::SQLString::caseCompare(class sql::SQLString const &)const " (?caseCompare@SQLString@sql@@QBEHABV12@@Z)
1>mysqlcppconn-static.lib(mysql_prepared_statement.obj) : warning LNK4217: locally defined symbol ??0exception@std@@QAE@ABQBDH@Z (public: __thiscall std::exception::exception(char const * const &,int)) imported in function "public: __thiscall std::bad_alloc::bad_alloc(void)" (??0bad_alloc@std@@QAE@XZ)
1>mysqlcppconn-static.lib(mysql_debug.obj) : warning LNK4217: locally defined symbol _getenv imported in function "public: __thiscall sql::mysql::MySQL_DebugLogger::MySQL_DebugLogger(void)" (??0MySQL_DebugLogger@mysql@sql@@QAE@XZ)
1>mysqlcppconn-static.lib(mysql_debug.obj) : warning LNK4217: locally defined symbol _printf imported in function "public: void __thiscall sql::mysql::MySQL_DebugLogger::enter(class sql::mysql::MySQL_DebugEnterEvent const *)" (?enter@MySQL_DebugLogger@mysql@sql@@QAEXPBVMySQL_DebugEnterEvent@23@@Z)
1>mysqlcppconn-static.lib(mysql_debug.obj) : warning LNK4217: locally defined symbol _vprintf imported in function "public: void __cdecl sql::mysql::MySQL_DebugLogger::log_va(char const * const,char const * const,...)" (?log_va@MySQL_DebugLogger@mysql@sql@@QAAXQBD0ZZ)
1>mysqlcppconn-static.lib(mysql_debug.obj) : warning LNK4217: locally defined symbol _strstr imported in function "public: __thiscall sql::mysql::MySQL_DebugEnterEvent::MySQL_DebugEnterEvent(unsigned int,char const * const,char const * const,class boost::shared_ptr<class sql::mysql::MySQL_DebugLogger> const &)" (??0MySQL_DebugEnterEvent@mysql@sql@@QAE@IQBD0ABV?$shared_ptr@VMySQL_DebugLogger@mysql@sql@@@boost@@@Z)
1>mysqlcppconn-static.lib(mysql_ps_resultset_metadata.obj) : warning LNK4217: locally defined symbol _strstr imported in function "char * __cdecl std::_Allocate<char>(unsigned int,char *)" (??$_Allocate@D@std@@YAPADIPAD@Z)
1>mysqlcppconn-static.lib(mysql_resultset_metadata.obj) : warning LNK4049: locally defined symbol _strstr imported
1>mysqlcppconn-static.lib(mysql_util.obj) : warning LNK4217: locally defined symbol _strtod imported in function "long double __cdecl sql::mysql::util::strtold(char const *,char * *)" (?strtold@util@mysql@sql@@YAOPBDPAPAD@Z)
1>mysqlcppconn-static.lib(mysql_art_resultset.obj) : warning LNK4217: locally defined symbol __strtoi64 imported in function "public: __int64 __thiscall sql::mysql::MyVal::getInt64(void)" (?getInt64@MyVal@mysql@sql@@QAE_JXZ)
1>mysqlcppconn-static.lib(mysql_ps_resultset.obj) : warning LNK4217: locally defined symbol __strtoi64 imported in function "public: __thiscall sql::SQLException::SQLException(class sql::SQLException const &)" (??0SQLException@sql@@QAE@ABV01@@Z)
1>mysqlcppconn-static.lib(mysql_resultset.obj) : warning LNK4049: locally defined symbol __strtoi64 imported
1>mysqlcppconn-static.lib(mysql_art_resultset.obj) : warning LNK4217: locally defined symbol __strtoui64 imported in function "public: unsigned __int64 __thiscall sql::mysql::MyVal::getUInt64(void)" (?getUInt64@MyVal@mysql@sql@@QAE_KXZ)
1>mysqlcppconn-static.lib(mysql_ps_resultset.obj) : warning LNK4217: locally defined symbol __strtoui64 imported in function __unwindfunclet$??0SQLException@sql@@QAE@ABV01@@Z$0
1>mysqlcppconn-static.lib(mysql_resultset.obj) : warning LNK4049: locally defined symbol __strtoui64 imported
1>mysqlcppconn-static.lib(mysql_client_api.obj) : error LNK2001: unresolved external symbol __imp___CrtDbgReportW
1>mysqlcppconn-static.lib(mysql_art_resultset.obj) : error LNK2001: unresolved external symbol __imp___CrtDbgReportW
[snip]
1>mysqlcppconn-static.lib(mysql_native_statement_wrapper.obj) : error LNK2001: unresolved external symbol __imp___wassert
1>mysqlcppconn-static.lib(mysql_art_rset_metadata.obj) : error LNK2001: unresolved external symbol __imp___wassert
[snip]
1>mysqlcppconn-static.lib(mysql_uri.obj) : error LNK2019: unresolved external symbol __imp__memchr referenced in function "public: static char const * __cdecl std::char_traits<char>::find(char const *,unsigned int,char const &)" (?find@?$char_traits@D@std@@SAPBDPBDIABD@Z)
1>mysqlcppconn-static.lib(mysql_metadata.obj) : error LNK2001: unresolved external symbol __imp__memchr
1>mysqlcppconn-static.lib(mysql_resultset.obj) : error LNK2019: unresolved external symbol __imp__div referenced in function "public: virtual __int64 __thiscall sql::mysql::MySQL_ResultSet::getInt64(unsigned int)const " (?getInt64@MySQL_ResultSet@mysql@sql@@UBE_JI@Z)