Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/126.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/56.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ c++;使用c++;连接器_C++_Mysql_Mysql Connector - Fatal编程技术网

C++ c++;使用c++;连接器

C++ c++;使用c++;连接器,c++,mysql,mysql-connector,C++,Mysql,Mysql Connector,试图建立一个简单的mysql连接,但是得到了一个bad\u alloc,我想不出如何解决这个问题,即使看到类似的帖子 这是我的密码 #include <iostream> #include <stdlib.h> #include <sstream> #include <memory> #include <string> #include <stdexcept> #include "mysql_connection.h" #

试图建立一个简单的mysql连接,但是得到了一个
bad\u alloc
,我想不出如何解决这个问题,即使看到类似的帖子

这是我的密码

#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;
}
#包括
#包括
#包括
#包括
#包括
#包括
#包括“mysql\u connection.h”
#包括“cppconn\driver.h”
#包括“cppconn\statement.h”
#包括“cppconn\connection.h”
#包括“cppconn\exception.h”
#包括“cppconn\prepared_statement.h”
#包括“cppconn\statement.h”
使用名称空间std;
使用名称空间sql;
int main()
{
司机*司机;
连接*连接;
声明*stmt;
driver=get_driver_instance();
conn=driver->connect(“127.0.0.1:3306”,“根”,“根”);//在这里中断
stmt=conn->createStatement();
stmt->execute(“使用mydb”);
返回0;
}
我使用的是
mysql-connector-c++-1.1.7
mysqlcppconn.lib
用作依赖项
mysqlcppconn.dll
.exe
位于同一目录中

这里是MysqlConn.exe 0x0000 07FEFD39 A06D中的错误<代码>异常:微软C++异常:STD::BADYOLL在内存位置0x000 000 000 014F5D0。< /代码> < /P>


谢谢,我在linux上也犯了同样的错误

错误是:我正在使用
g++-4.8
构建项目


问题在于用于构建项目的构建工具的版本(gcc、msvs、clang)

我也有这个错误。就我而言,我是在Windows中使用VS2015进行编译的

我第一次选择编译MySQL库的静态版本。后来我决定编译动态版本。这一次,内存中的错误bad_alloc消失了

解决方案是回滚CPPCONN_PUBLIC_FUNC=配置


转到Project属性页,在C++ >预处理器>预处理器定义中,并移除项<代码> CPPPnnRealPuxyFunc=“

mysqlcppconn.lib用作依赖项,它与.exe位于同一目录中--生成过程中使用.lib文件,与
exe
的位置无关。您似乎不知道用于构建应用程序的组件以及运行应用程序所涉及的组件。也许您在运行时应该使用的MySql dll与您的可执行文件不兼容?对不起,我是说.dll,我会解决这个问题。我遵循这一介绍,使用dymanic而不是statis build。根据这一点,我想我不再需要任何mysql DLL了(嗯,你需要确保DLL的(看起来他们使用C++标准库),与您的编译器版本的标准库兼容。换句话说,如果这些DLL是使用VS 2013创建的,而您使用的是另一版本的Visual Studio,则会出现运行时问题。如果是静态库,则同样适用。静态库必须使用相同的编译器、编译器选项等构建。a这是你的应用程序。我使用了这个连接器mysql-connector-c++-1.1.7-winx64.msi,库机器类型为x64。你能告诉我我能做些什么来检查你的建议吗?嗯,好的,是的,我在使用vs2015,但我想我找不到关于visual studio 2015的dll的信息,我不可能是唯一一个有这种问题的人。也许我是e只有一个人不知道这一点,所以;)