简体   繁体   English

如何将MySQL连接器/ C ++ 1.1添加到Visual Studio 2010项目?

[英]How to add MySQL connector/C++ 1.1 to Visual Studio 2010 project?

I'm trying to add MySQL Connector/C++ to my visual Studio 2010 project. 我正在尝试将MySQL Connector / C ++添加到我的visual Studio 2010项目中。

I followed the steps ( here, mysql docs ) to add it to Visual Studio (I also added Boost in the "Additional include Directories"). 我按照步骤( 这里,mysql文档 )将它添加到Visual Studio(我还在“附加包含目录”中添加了Boost)。

It asked for a "sqlstring.h" file ( How a release can miss a file ?! ), so I had it from the source files ( mysql source archives ). 它要求一个“sqlstring.h”文件(一个版本如何错过一个文件?!),所以我从源文件( mysql源档案 )获得它。

Then, It asked for libmyql.lib, I had the lib directory of MySQL Server 5.5\\lib. 然后,它要求libmyql.lib,我有MySQL Server 5.5 \\ lib的lib目录。

And now, I'm on this error: 而现在,我正在犯这个错误:

Error 127 error LNK1120: 31 unresolved externals C:\\Users\\Haks\\Documents\\Visual Studio 2010\\Projects\\ProductManager\\Debug\\ProductManager.exe ProductManager 错误127错误LNK1120:31未解析的外部C:\\ Users \\ Haks \\ Documents \\ Visual Studio 2010 \\ Projects \\ ProductManager \\ Debug \\ ProductManager.exe ProductManager

Error 60 error LNK2001: unresolved external symbol "__declspec(dllimport) bool __cdecl std::operator<<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 &,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (__imp_??$?MDU?$char_traits@D@std@@V?$allocator@D@1@@std@@YA_NABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@0@0@Z) C:\\Users\\Haks\\Documents\\Visual Studio 2010\\Projects\\ProductManager\\ProductManager\\mysqlcppconn-static.lib(mysql_ps_resultset.obj) ProductManager 错误60错误LNK2001:未解析的外部符号"__declspec(dllimport) bool __cdecl std::operator<<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 &,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (__imp_??$?MDU?$char_traits@D@std@@V?$allocator@D@1@@std@@YA_NABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@0@0@Z) C:\\ Users \\ Haks \\ Documents \\ Visual Studio 2010 \\ Projects \\ ProductManager \\ ProductManager \\ mysqlcppconn-static.lib(mysql_ps_resultset.obj)ProductManager

So, maybe it's because I got the binary release of MySQL Connector/C++ 1.1 and maybe it's not compatible with VS 2010... 所以,也许是因为我得到了MySQL Connector / C ++ 1.1的二进制版本,也许它与VS 2010不兼容......

But I don't find the good way to compile the source files, and I never use Boost or CMake and it's seem to be needed. 但我找不到编译源文件的好方法,而且我从不使用Boost或CMake,而且似乎需要它。

I found no reference to my problem, so if someone got a response or a good way, it will be very useful for me and a lot of people I think. 我没有找到任何关于我的问题的提法,所以如果有人得到回应或者有好的方式,那对我和我想的很多人来说都会非常有用。

Thank you 谢谢

First of all, thanx to the dar7yl for pointing in the right direction. 首先,thanx到dar7yl指向正确的方向。

After spending much time debugging mysql connection (VS 2010, C++), which proves to be a much hair raising experience, I am compelled to say something about it. 花了很多时间调试mysql连接(VS 2010,C ++),这被证明是一个很大的头发提升经验,我不得不说一些关于它的事情。 (assumed you setup C++ include files directory and link directory + additional dependence file correctly, else refer to the website on point 2 for reference) (假设您正确设置了C ++包含文件目录和链接目录+附加依赖文件,否则请参考第2点的网站以供参考)

0.) Yes, we need boost library. 是的,我们需要加强库。 Download boost library (search google) and unpack it into your development folder and have your c++ additional include directories point to it(boost main directory, not the boost child directory). 下载boost库(搜索谷歌)并将其解压缩到您的开发文件夹中,并让您的c ++附加包含目录指向它(boost主目录,而不是boost子目录)。

1.) Need to be clear on the difference in VS solution configuration mode "debug" and "release". 1.)需要明确VS解决方案配置模式“debug”和“release”的区别。 The .lib files provided provided after full installation of MYSQL under directory ...\\mysql\\Connector C++ ____\\lib\\ has two directories of debug and opt for use with solution mode "debug" and "release" accordingly. 在目录下完全安装MYSQL后提供的.lib文件... \\ mysql \\ Connector C ++ ____ \\ lib \\有两个debug和opt目录,用于解决方案模式“debug”和“release”。 The main difference being "debug" mode uses the extra .pdb files. 主要区别是“调试”模式使用额外的.pdb文件。

2.) http://dev.mysql.com/doc/refman/5.1/en/connector-cpp-apps-windows-visual-studio.html gives a very detail outline for VS2008 mysql connection setup. 2.) http://dev.mysql.com/doc/refman/5.1/en/connector-cpp-apps-windows-visual-studio.html给出了VS2008 mysql连接设置的非常详细的概述。 Particularly the need to include under [Project, Properties tree view, under C++, Preprocessor] two statement of CPPCONN_PUBLIC_FUNC= and HAVE_INT8_T=1 特别需要在[Project,Properties tree view,C ++,Preprocessor]下包含CPPCONN_PUBLIC_FUNC =和HAVE_INT8_T = 1的两个语句

3.) be clear which mode of connection you would like with the library, mysqlcppconn.lib is dll based while mysqlcppconn-static.lib is static based. 3.)清楚你想要哪种模式的连接,mysqlcppconn.lib是基于dll的,而mysqlcppconn-static.lib是基于静态的。 For dll based lib, related dll mysqlcppconn.dll needs to be deposited into \\windows\\system32\\ or other system path for access. 对于基于dll的lib,需要将相关的dll mysqlcppconn.dll存入\\ windows \\ system32 \\或其他系统路径进行访问。
For static connection remember its using extern C connection so you will need libmysql.lib + libmysql.dll (libmysql.pdb if under "debug") from ...\\mysql\\connectorc c ___\\, if not you will get the unresolved external symbol error LNK 2019. So promptly update your c++ include files directory, link include file directory, additional dependency accordingly and deposite the .dll file into system path or ....\\windows\\system32\\ 对于静态连接,请记住它使用extern C连接,因此您将需要来自... \\ mysql \\ connectorc c ___ \\的libmysql.lib + libmysql.dll(libmysql.pdb,如果在“debug”下),如果不是,您将获得未解析的外部符号错误LNK 2019.因此,请及时更新您的c ++包含文件目录,链接包含文件目录,相应的附加依赖项,并将.dll文件存入系统路径或.... \\ windows \\ system32 \\

4.) At this point, things should work for some of us. 4.)在这一点上,事情应该对我们中的一些人有用。 And no, it didn't work for me. 不,它对我不起作用。 Reason? 原因? Library comparability issue as outlined by dar7yl. dar7yl概述的库可比性问题。 So if this is the case, download source code for the connector under http://dev.mysql.com/downloads/connector/cpp/ by select platform to source code. 因此,如果是这种情况,请通过选择平台下载源代码,在http://dev.mysql.com/downloads/connector/cpp/下载连接器的源代码。 Unpack and it get a bit complicated from here. 打开包装,从这里开始变得有点复杂。 No VS solution or project files? 没有VS解决方案或项目文件? No worries, see the cmake__.txt file? 不用担心,看到cmake __。txt文件? that's our solution. 这是我们的解决方案。 Download cmake and have the source directory and destination directory point to your unpacked source code directory. 下载cmake并让源目录和目标目录指向解压缩的源代码目录。 Then open cmake__.txt in the directory and search for keyword "boost" and update the boost directory to point to your boost directory. 然后在目录中打开cmake __。txt并搜索关键字“boost”并更新boost目录以指向您的boost目录。 Run configure and set to VS 2010, check the outlined configuration and change whatever is necessary Name/Value table then press generate. 运行configure并设置为VS 2010,检查概述的配置并更改所需的名称/值表,然后按generate。 By now your project + solution files should have been generated, open it and you will see many projects. 到目前为止,您的项目+解决方案文件应该已生成,打开它,您将看到许多项目。 We are only concerned with mysqlcppconn and mysqlcppconn-static. 我们只关心mysqlcppconn和mysqlcppconn-static。 check and update the include files, link files + dependency in the two project's property and compile. 检查并更新两个项目属性中的包含文件,链接文件+依赖项并进行编译。 Drop the generated .lib + .dll (and .pdb if using "debug" mode) into the corresponding directories and your project should work now. 将生成的.lib + .dll(以及.pdb,如果使用“debug”模式)放入相应的目录中,您的项目现在应该可以正常工作。

By this point mysql connection now works for me, hope it works for you too. 到目前为止,mysql连接现在适用于我,希望它也适合你。 Some details might be missing from the above and I do apologies. 上面可能会遗漏一些细节,我很抱歉。

Just a small addition to dddddd great post. 只是dddddd伟大帖子的一小部分。 If you are compiling on Windows7 then you will probably get some 'unresolved externals' from the libmysql.lib library. 如果您在Windows7上进行编译,那么您可能会从libmysql.lib库中获得一些“未解析的外部”。 I found this was due to the fact that the libmysql.lib came from a 64bit installation of the server. 我发现这是因为libmysql.lib来自服务器的64位安装。 You will need to find the 32 bit version and link with that, or just install the 32 bit server instead. 您需要找到32位版本并与之链接,或者只安装32位服务器。

I finally got MySQL Connector/C++ working with visual Studio 2010 by downloading the source and compiling it with the same settings as my project. 我终于通过下载源代码并使用与我的项目相同的设置编译它来使MySQL Connector / C ++与Visual Studio 2010一起工作。 It still warns about SqlString library: 它仍然警告SqlString库:

j:\mysql-connector-c++-1.1.0\cppconn\sqlstring.h(36): warning C4251: 'sql::SQLString::realStr' : class 'std::basic_string<_Elem,_Traits,_Ax>' needs to have dll-interface to be used by clients of class 'sql::SQLString'

but, it seems to be ok with that. 但是,似乎没关系。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM