Trying to build a simple mysql connection, but getting a bad_alloc and I can't figure out how to solve this, even looking at similar posts
here is my code
#include <iostream>
#include <stdlib.h>
#include <sstream>
#include <memory>
#include <string>
#include <stdexcept>
#include "mysql_connection.h"
#include "cppconn\driver.h"
#include "cppconn\statement.h"
#include "cppconn\connection.h"
#include "cppconn\exception.h"
#include "cppconn\prepared_statement.h"
#include "cppconn\statement.h"
using namespace std;
using namespace sql;
int main()
{
Driver *driver;
Connection *conn;
Statement *stmt;
driver = get_driver_instance();
conn = driver->connect("127.0.0.1:3306", "root", "root"); // breaks here
stmt = conn->createStatement();
stmt->execute("USE mydb");
return 0;
}
I'm using mysql-connector-c++-1.1.7
mysqlcppconn.lib is used as a dependencies
mysqlcppconn.dll is located in the same dir as the .exe is.
Here is the error Exception thrown at 0x000007FEFD39A06D in MysqlConn.exe: Microsoft C++ exception: std::bad_alloc at memory location 0x000000000014F5D0.
Thanks
I also had this error. In my case I am compiling using VS2015 in Windows.
First time I choose compile static version of the MySQL lib. Then later I decided to compile the dynamic version. This time the error bad_alloc at memory went off.
The solution is rolling back the CPPCONN_PUBLIC_FUNC= configuration.
Go to project Property Pages, under C++ > Preprocessor > Preprocessor Definitions and remove the item CPPCONN_PUBLIC_FUNC=".
I had the same error on linux.
The error was : I was using g++-4.8 to build the project
The issue lies on the version of the build tools (gcc,msvs,clang) used to build the project
Related
I am getting an error saying namespace "bsoncxx::v_noabi::builder::basic" has no member "make_document", I have already added required included as per mentioned in the tutorial.
I am using mongo-cxx-driver-r3.1.1 version.
i have followed example from here
here is what I have tried
#include "maxi.h"
#include <cstdlib>
#include <iostream>
#include <bsoncxx/builder/basic/array.hpp>
#include <bsoncxx/builder/basic/document.hpp>
#include <bsoncxx/builder/basic/kvp.hpp>
#include <mongocxx/client.hpp>
#include <mongocxx/instance.hpp>
using bsoncxx::builder::basic::kvp;
using bsoncxx::builder::basic::make_document;// here is error
using bsoncxx::type;
mongocxx::instance inst{};
mongocxx::client conn{ mongocxx::uri{ "mongodb://localhost:27017" } };
see image here
I have already tested MongoDB driver after compiling and its working perfectly. I need to use make_document option for some reason in order to achieve my goal.
Not sure possible bsoncxx::builder::basic::make_document; option may have been removed or replaced with something else which I don't know.
In the current master branch, document.hpp file contains make_document method.
if I'm not mistaken you are using stable release version.
Take a look here.
Using declaration “not found” in MongoDB c++ driver
I'm trying to use MySQL Connector/C++ within Xcode. I have installed MySQL server. I also installed MySQL Connector/C++ and Boost using brew. I believe all files are where they should be.
I've included library search paths:
1) /usr/local/mysql-5.6.24-osx10.8-x86_64/lib
2) /usr/local/mysql/lib
I am just trying to get simple code to run before I dive a little deeper:
#include <stdlib.h>
#include <iostream>
#include "mysql_connection.h"
#include "mysql_driver.h"
#include <cppconn/driver.h>
#include <cppconn/exception.h>
#include <cppconn/resultset.h>
#include <cppconn/statement.h>
#include <cppconn/prepared_statement.h>
using namespace std;
int main(int argc, const char * argv[]) {
sql::mysql::MySQL_Driver *driver;
sql::Connection *con;
driver = sql::mysql::get_mysql_driver_instance();
con = driver->connect("tcp://127.0.0.1:3306", "user", "password");
delete con;
return 0;
}
The error I'm getting is: ld: library not found for -libmysqlcppconn
Any help would be greatly appreciated!
If you are using the Static MySQL Connector/C++ Library, did you link both library files: libmysqlcppconn-static.a and libmysqlclient.a? Do that in Xcode in the "Build Phases" tab under "Link Binary With Libraries" section. After you add those files make sure that the library search paths you provided point to the file locations.
For Dynamic Library instead you link the libmysqlcppconn.so file.
I'm using GMP and getting an illegal instruction that I have found to be caused by mpf_set_d. I'm programming in Netbeans with cygwin in c++.
Thanks in advance!
Edit:
I have a folder containing the following files:
.dep.inc, cyggcc_s-seh-1.dll, cyggmp-10.dll, cyggmpxx-4.dll, cygstdc++-6.dll, cygwin1.dll, my executable, gmp.h, gmpxx.h, libgmp.a, libgmp.la, libgmp.lai, libgmp.lai, libgmp.libcmd, libgmpxx.a, libgmpxx.la, libgmpxx.lai, main.cpp, main.o, main.o.d, Makefile, text file needed for program and folders needed for program.
I have tried many things, one of which was to add an executable to this folder that ran the following code:
#include <cstdlib>
#include <iostream>
#include <stdio.h>
#include "gmpxx.h"
#include <stdarg.h>
#include <string>
using namespace std;
int main()
{
mpf_t a;
mpf_init(a);
mpf_set_d(a,3.1415926535);
cout << "works" << endl;
}
Running this on my own computer with GMP installed gives me 'works' after which it closes, on another computer that does not have GMP installed it throws an error and closes. The error is an exception: status_illegal_instruction.
I can't give you my code but I can post snippets. Please tell me if more information is necessary!
Thanks again.
Edit 2:
The same counts for mpf_set_str as well as the c++ wrapper.
Scroll down for (part of) the solution that I found:
I'm on a Windows 8.1, 64 bit laptop
It is my first time trying to connect C++ to MySQL using the mentioned connector.
The error is as follow:
Error 1 error LNK2019: unresolved external symbol "class sql::mysql::MySQL_Driver * __cdecl sql::mysql::get_driver_instance(void)" (?get_driver_instance#mysql#sql##YAPAVMySQL_Driver#12#XZ) referenced in function _main C:\Users\user\documents\visual studio 2013\Projects\Profile\Profile\Profile.obj Profile
This is my main code:
// Profile.cpp : Defines the entry point for the console application.
#include "stdafx.h"
#include <iostream>
#include <string>
#include "mysql_connection.h"
#include "mysql_driver.h"
#include <cppconn/driver.h>
#include <cppconn/exception.h>
#include <cppconn/resultset.h>
#include <cppconn/statement.h>
#include <cppconn/prepared_statement.h>
#define dbHOST "tcp://127.0.0.1:3306"
#define dbUSER "root"
#define dbPASS "root"
#define dbDB "db_test"
using namespace std;
using namespace sql;
int main()
{
sql::mysql::MySQL_Driver *driver;
sql::Connection *con;
driver = sql::mysql::get_driver_instance();
con = driver->connect(dbHOST, dbUSER, dbPASS);
delete con;
system("pause");
return 0;
}
I have followed the instructions from this mysql site for the static installation.
I have also Google quite a lot with the error.
Some suggested it could be the connector files different for 64bit and 32bits - I've tried downloading both (they are installed in Program Files and Program Files (x86) accorindgly. but the error persists.
One thing to note, when I link it with the 32bit connector files, it will have a huge load more of errors.
Makes me wonder after all the search, is it that VS Express 2013 is not compatible to connect with MySQL thus far?
I heard ppl saying using the Qt would be easier, but I still want to try this out.
Please let me know if my question is vague or if you need more information.
Thanks in advance!
SOLUTION I FOUND
I don't want to add it as an answer because it does not remedy the question I asked.
Anyway, I found a link which gives fairly simple instructions which has got it to work. Would still appreciate if anyone is willing to look into my original issue.
:)
I am trying to develop an application that uses MySQL using C++. I downloaded the library from their website and I have attempted to compile the following code:
#include <iostream>
#include <windows.h>
#include <mysql.h>
using namespace std;
int main()
{
MYSQL *connection, mysql;
MYSQL_RES *result;
MYSQL_ROW row;
mysql_init(&mysql);
}
The line that has mysql_init(&mysql); gives me a compilation error
undefined reference to `mysql_init#4'
I am guessing this is due to a library error. I am linking mysqlclient.lib and libmysql.lib in that order. What do I need to do to make this compile without requiring a dll file? Is that possible? Thank you.
Note: I am using mingw32 on Windows 7 x64 to develop an application for Windows.
Maybe this link will help. It states that mysqlclient.lib is the static library and libmysql.lib is the dynamic library, so I don't think you should be linking both.
http://dev.mysql.com/doc/refman/5.0/en/building-clients.html