I am using the MySQL Connector/C++ in my project for interaction with the MySQL database. The project compiles fine. However, when I run it I get an error
Unhandled exception at at 0x000007FEFD30B16D in ProjectName.exe:
Microsoft C++ exception: std::bad_alloc at memory location 0x00000000036FC2A0.
on the first line using the database. In this case I am executing a MySQL statement
sql::Statement* stmt = mSqlCon->con->createStatement();
stmt->execute("CREATE TABLE IF NOT EXISTS ..."); // Unhandled exception
When I compile for Release, everything works fine and no errors are thrown.
My environment:
Visual Studio project settings and libraries that might be relevant:
_DEBUG;_MBCS;_CRT_SECURE_NO_WARNINGS
Multi-threaded Debug (/MTd)
Both (/RTC1, equiv. to /RTCsu) (/RTC1)
My thoughts: This error occurred after I started using the boost library. This required to change some project settings, like preprocessor definition _DEBUG
(which should be used for debug builds anyway, but was not used before to be able to build the connector). So I think the problem is using the release version of MySQL Connector/C++ in the debug build of the project. Everything works fine in the release build. However, I cannot find any debug version of the connector, nor can I build it myself or reinstall it with debug libraries... Is there another solution to my problem (or did I not search good enough)?
I read that there should be a debug
folder in my MySQL folder C:\\Program Files\\MySQL\\MySQL Connector C++ 1.1.6\\lib
, but it only contains an opt
folder with the release build (which I am using).
Any help is very much appreciated!
Yes you are right, the problem is behind linking a project in Debug configuration with the Release library inside the opt folder. All you have to do is compile yourself the source code of the library in Debug configuration:
(path\\to\\)cmake.exe -G "Visual Studio 14 2015 Win64" -DCMAKE_BUILD_TYPE=Debug
and run it; this way you are telling CMake to build a project that you can compile with the version 14 of Visual Studio (you can choose other versions, if you want to have a look type cmake -h
) for a x64 Machine with Debug configuration. MYSQLCONNCPP.sln
. Change the output file type to static if you wish to create a static library. MYSQLCONNCPP
project to build. a) Now go to Project Properties, and add HAVE_STRUCT_TIMESPEC
to the Preprocessor Definitions (this prevents timespec redefinition) b) Add /EHsc
to C++ -> Command Line (this prevents errors related to the exception handler) c) Change the project's Runtime Library to match the one you want to link the library to: for instance in my case I had to set it as /MDd
I got the same problem. It happens because of discrepency in the configuration. The client application can be debugged if the mysql wrapper is a separate .lib file. If the Mysql release version has been downloaded and installed then you need to build a wrapper to connect/query etc and export it to other projects as a release .lib. The Mysql can be debugged using trace option provided. MYSQL DEBUG TRACE C++
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.