MySQL Connector Issues - Binding and More

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:

 /*tons of includes here*/ int main(int argc, const char *argv[]) { Driver *driver; Connection *con; Statement *stmt; ResultSet *res; PreparedStatement *prep_stmt; Savepoint *savept; int updatecount = 0; /* initiate url, user, password and database variables */ 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(); /*blah blah yada yada*/ } catch (std::runtime_error &e) { cout << "ERROR: runtime_error in " << __FILE__; //cout << " (" << __func__ << ") on line " << __LINE__ << endl; cout << "ERROR: " << e.what() << endl; return EXIT_FAILURE; } return EXIT_SUCCESS; } // main() 

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.

+4
source share
3 answers

I had the same problem "failed to start correctly (0xc000007b)". The problem was that I did not use the correct DLL (instead of x64 I used x86), although I installed (and reinstalled) mysql for the 64-bit version.

I added to the PATH variable "C: \ MySQL \ Connector C ++ 1.1.3 \ lib \ opt" where mysqlcppconn.dll is located (for x64). However, in my PATH there is another directory (lua installation) that has mysqlcppconn.dll (for x86). Since the x86 directory was installed before the MySQL directory, the x86 dll was loaded and, therefore, "could not start ..."

To avoid this, I copied mysqlcppconn.dll to the directory for debugging the project.

+2
source

Try creating a new project and just create a simple DB connector, I don't have windows available here, so I can only show your Linux example:

The difference I see is that you use prepare_statement, can you try its statement and just include mysqlcppconn.dll in your linker and see if this "small project" compiles? You may have too many libraries, but a simple test will make it easier to identify your problem if this solves your problem, than you know that these libraries should not be included in each other.

If this does not work, tell me and I will try to extend the answer.

Here my includes:

 #include "mysql_connection.h" #include "mysql_driver.h" #include <cppconn/driver.h> #include <cppconn/exception.h> #include <cppconn/resultset.h> #include <cppconn/statement.h> 

int main () {

 sql::Driver *driver; sql::Connection *con; sql::Statement *stmt; sql::ResultSet *res; sql::Statement *pstmt; try{ driver = get_driver_instance(); con = driver->connect("localhost", "root", "root"); con->setSchema("test"); stmt = conn->createStatement(); /*blah blah yada yada*/ }catch(sql::SQLException &e){ std::cout<<e.what(); } 

}

0
source

I had the same β€œunable to start” problem, and after the pain she decided. Unfortunately, your disclaimer on your first post says that you have already tried my solution, but I will post the process that I used to prove to myself that I had the wrong type of DLL (initially I was also sure that I used the correct bitt dll). If you are still sure that you have the correct DLL / LIB cue ball, go to the "Debugging Using Process Monitor" section.

My problem was that my post build scripts copied the DLL from the wrong location. I spent a lot of time trying to make sure that my DLL has the right material, but it seems that my post-build scripts were not copied from this directory, so I copied the x64 DLLs along with my x86 application.

Tools: -Dependency walker (http://www.dependencywalker.com/) -Process Monitor (http://technet.microsoft.com/en-ca/sysinternals/bb896645.aspx)

Procedure: -Make a project that compiles and runs without problems. I made a console application and inserted the MySQL connector sample code into the code. This is below. Note that I used #pragma comment (lib) to enable lib, so you don’t even need to link to the library, including directories only.

 /* Copyright 2008, 2010, Oracle and/or its affiliates. All rights reserved. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License. There are special exceptions to the terms and conditions of the GPL as it is applied to this software. View the full text of the exception in file EXCEPTIONS-CONNECTOR-C++ in the directory of this software distribution. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ /* Standard C++ includes */ #include "stdafx.h" #include <stdlib.h> #include <iostream> /* Include directly the different headers from cppconn/ and mysql_driver.h + mysql_util.h (and mysql_connection.h). This will reduce your build time! */ #include "mysql_connection.h" #include <cppconn/driver.h> #include <cppconn/exception.h> #include <cppconn/resultset.h> #include <cppconn/statement.h> #pragma comment(lib,"mysqlcppconn.lib") #pragma comment(lib,"libmysql.lib") using namespace std; int main(void) { cout << endl; cout << "Running 'SELECT 'Hello World!' AS _message'..." << endl; try { sql::Driver *driver; sql::Connection *con; sql::Statement *stmt; sql::ResultSet *res; /* Create a connection */ driver = get_driver_instance(); con = driver->connect("tcp://127.0.0.1:3306", "root", "password"); /* Connect to the MySQL test database */ con->setSchema("test"); stmt = con->createStatement(); res = stmt->executeQuery("SELECT 'Hello World!' AS _message"); while (res->next()) { cout << "\t... MySQL replies: "; /* Access column data by alias or column name */ cout << res->getString("_message") << endl; cout << "\t... MySQL says it again: "; /* Access column fata by numeric offset, 1 is the first column */ cout << res->getString(1) << endl; } delete res; delete stmt; delete con; } catch (sql::SQLException &e) { cout << "# ERR: SQLException in " << __FILE__; cout << "(" << __FUNCTION__ << ") on line "<< __LINE__ << endl; cout << "# ERR: " << e.what(); cout << " (MySQL error code: " << e.getErrorCode(); cout << ", SQLState: " << e.getSQLState() << " )" << endl; } cout << endl; return EXIT_SUCCESS; } 

If this code does not work as soon as you have the directories installed, you really need to double-check that the DLLs and LIBs that you use are the correct 32/64 bit. You can use the dependent walker for this.

How to use the dependency walker: 1) Drag the DLL or EXE into the DepWalk window. In the ugly list of modules (window above the log), find the DLL / EXE that you dragged and make sure that the CPU type in the CPU column is what you expect.

Debugging the monitoring process: If the toy code above is compiled for you, now you are talking! You have an example of an application that launches correctly, and your application with broken ads that does not. Launch the process monitor, set the filter to enable only your toy application, and run it. File-> save this log, change the filter to your damaged application process name, and then do it again using the broken application. Now you can compare the fact that the two applications run in mySQL DLL, and perhaps figure out where they break. In my case, I noticed that he was loading libmysql.dll in the right place, and then hunting in other places. I correctly understood that this meant that I had the wrong LibMySQL.dll. This may not be your problem, but I'm sure you will learn about the process monitor.

0
source

Source: https://habr.com/ru/post/1433963/


All Articles