简体   繁体   中英

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.

I followed the steps ( here, mysql docs ) to add it to Visual Studio (I also added Boost in the "Additional include Directories").

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 ).

Then, It asked for libmyql.lib, I had the lib directory of MySQL Server 5.5\\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

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

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...

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.

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.

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. (assumed you setup C++ include files directory and link directory + additional dependence file correctly, else refer to the website on point 2 for reference)

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).

1.) Need to be clear on the difference in VS solution configuration mode "debug" and "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. The main difference being "debug" mode uses the extra .pdb files.

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. Particularly the need to include under [Project, Properties tree view, under C++, Preprocessor] two statement of CPPCONN_PUBLIC_FUNC= and 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. For dll based lib, related dll mysqlcppconn.dll needs to be deposited into \\windows\\system32\\ or other system path for access.
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\\

4.) At this point, things should work for some of us. And no, it didn't work for me. Reason? Library comparability issue as outlined by 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. Unpack and it get a bit complicated from here. No VS solution or project files? No worries, see the cmake__.txt file? that's our solution. Download cmake and have the source directory and destination directory point to your unpacked source code directory. Then open cmake__.txt in the directory and search for keyword "boost" and update the boost directory to point to your boost directory. Run configure and set to VS 2010, check the outlined configuration and change whatever is necessary Name/Value table then press 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. 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.

By this point mysql connection now works for me, hope it works for you too. Some details might be missing from the above and I do apologies.

Just a small addition to dddddd great post. If you are compiling on Windows7 then you will probably get some 'unresolved externals' from the libmysql.lib library. I found this was due to the fact that the libmysql.lib came from a 64bit installation of the server. You will need to find the 32 bit version and link with that, or just install the 32 bit server instead.

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. It still warns about SqlString library:

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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