问题
I'm trying to run a simple mysql-connector
(c++) application in debug mode, but it seems to fail when it gets to the following line (see full source below):
pstmt = con->prepareStatement(query);
and using the Local Windows Debugger in Visual Studio, it stops [at that line above] with this Exception Unhandled:
Unhandled exception at 0x00007FFD7921A388 in Database.exe: Microsoft C++ exception: std::bad_alloc at memory location 0x0000004F7E8FC920.
This same application runs fine if I set my active build configuration to Release
(VS 2017, Win10/64bit). I'm using mysql-connector-c++-noinstall-1.1.12
While in debug for the Active build configuration, if I just hit ctrl+f5 (build without debugging) I get an alert/pop-up:
Microsoft Visual C++ Runtime Library
Program: ..\Database.exe
abort() has been called
(Press Retry to debug the application)
Any idea what I might be doing wrong here? At first I thought it was related to not building mysql-connector myself (per my previous post here: Trying to build mysql-connector-cpp on Windows).
EDIT: I tried using two different downloads of mysql-connector-c++
:
mysql-connector-c++-noinstall-1.1.12-winx64
Connector C++ 8.0
And they produce the following error/crash windows respectively:
The ordinal 4699 could not be located in the dynamic link library c:\users\..\Database\x64\Debug\mysqlcppconn.dll
The ordinal 4699 could not be located in the dynamic link library c:\WINDOWS\SYSTEM32\mysqlcppconn-7-vs14.dll
Thanks again!
Full source: https://pastebin.com/GmsNEEFa
回答1:
Regarding your previous post:
You should be able to build OK; the specific error indicated your link command was failing to find the SSL library, which you indicated you had on your system. My suggestion was to use nmake or create an MSVS project (there's nothing "wrong" with cmake ... but if you're going to use Microsoft's compiler, it's generally just much easier to use Microsoft's tools) and - most importantly - to use the correct "link path" syntax.
Regarding your current post:
Q: Did you install the MySQL Connector, following the instructions in here?
My previous suggestion still holds: if you have MSVS, then go into the IDE, create an MSVS C++ console-mode project, and cut/paste the code you posted to Pastebin into your new project. CREATE AN MSVS PROJECT.
Go into MSVS > Project > Properties and add a) the path to your MySQL includes, and b) the path to your MySql libraries.
Add the MySql dynamic library (LIB/vs14/mysqlcppconn8.lib) to your link command. Follow the instructions here.
Post back what you find. It should work. Please specify exactly what you did, and copy/paste the exact error message if it doesn't.
Once things are working ... then create your "actual" build scripts however you want. At least you'll have a good "reference" to fall back on.
'Hope that helps!
PS:
The binary .msi has two C/C++ connector libraries: a static library, and a dynamic .dll. You link to either one with a ".lib" file: "LIB/vs14/mysqlcppconn8.lib" for the .dll, or "LIB/vs14/mysqlcppconn8-static.lib" for the static library.
来源:https://stackoverflow.com/questions/54858015/bulding-mysql-connector-c-application-in-debug-on-windows-vs2k17