So I'm guys again. After a whole day trying to find a solution for connecting libmysql.lib and mysqlclient.lib, I did it carefully. So, I decided to go the other way and use the convenient MySQL connector.
In version 1.1.0, it uses boost, which I did not have available, and I do not want to waste time and draw everything, I decided to download 1.0.5.
So, I installed it, created a new project, linked all the necessary libraries, installed additional libraries and turned it on (well, as a rule, everything was done in accordance with this. To check the correct operation, I used this example:
#include <stdlib.h> #include <iostream> #include "driver.h" #include "exception.h" #include "resultset.h" #include "statement.h" #include "prepared_statement.h" int main(){ sql::Driver *driver; sql::Connection *con; sql::Statement *stmt; sql::ResultSet *res; sql::PreparedStatement *pstmt; try{ driver = get_driver_instance(); con = driver->connect("localhost", "root", "root"); con->setSchema("test"); /*blah blah yada yada*/ }catch(sql::SQLException &e){ std::cout<<e.what(); } }
I skipped part of the code because that is not the point here. Thus, the problem with this was an application error indicating the inability to start correctly (0xc000007b). Debugging did not help much, since this error occurred as soon as the program started, i.e. Even if I put an endless loop at the beginning, it will still work.
So, I thought: "It must be some mistake of this version, so I have to try a newer one." After that, I went ahead and downloaded the connector version 1.1.0, and also increased the libraries. Then, creating a new project, specify all the dependencies, like the first, but pointing to a newer version of the connector. In addition, I set up a new mysqlcppconn_EXPORTS link. So, the preparation was completed, and for testing I used the code for the MySQL site , well, as a rule, something like this:
int main(int argc, const char *argv[]) { Driver *driver; Connection *con; Statement *stmt; ResultSet *res; PreparedStatement *prep_stmt; Savepoint *savept; int updatecount = 0; string url(argc >= 2 ? argv[1] : DBHOST); const string user(argc >= 3 ? argv[2] : USER); const string password(argc >= 4 ? argv[3] : PASSWORD); const string database(argc >= 5 ? argv[4] : DATABASE); try { driver = get_driver_instance(); } catch (std::runtime_error &e) { cout << "ERROR: runtime_error in " << __FILE__;
And guess what? Yup, here again the linker error goes:
error LNK2001: unresolved external symbol _get_driver_instance
So please tell me what am I doing wrong? It would be very grateful.
I will indicate it explicitly and write it in bold so that there is no answer in this way. I definitely installed both Preferences β C / C ++ β General β Include Additional Directories, and Preferences β Linker β General β Additional Library Directories.
In addition, I added mysqlcppconn.lib to "Settings" β "Linker" β "Additional Dependencies".
In addition, I put mysqlcppconn.dll and libmysql.dll (yup, from the corresponding C ++ Connector versions) in the project folder, no problems with it.
Oh, and yes, I tried both with the CPPCONN_PUBLIC_FUNC= key and without it in the preprocessor definitions - no changes occurred.
As I said - with the same project settings, the version 1.0.5 of the connector does not work at the construction stage and version 1.1.0 - at the compilation stage.
ps I am using VS 2010, my OS is Windows 7 x64. Both projects and libraries are x32.