MySQL Connector / C BAD ACCESS崩溃(另一种情况)

时间:2013-03-19 07:23:18

标签: c++ exc-bad-access mysql-connector xcode4.6

我很抱歉这样一个noob问题,但是在编译最简单的程序连接到MySQL数据库并在那里执行“SELECT”命令时,我无法赢得与我的Xcode(4.6.1)的斗争。

该程序来自MySQL Connector / C ++的“examples”目录:

/* Standard C++ includes */
#include <stdlib.h>
#include <iostream>
#include <sstream>
#include <stdexcept>

#include "mysql_connection.h"
#include "mysql_driver.h"

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

std::string url;
std::string user;
std::string pass;
std::string database;

/**
 * Usage example for Driver, Connection, (simple) Statement, ResultSet
 */
int main(int argc, const char **argv)
{
    sql::Driver *driver;
    std::auto_ptr< sql::Connection > con;

    url = "tcp://127.0.0.1:3306";
    user = "john";
    pass = "john";
    database = "cunda_sales";

    try {
        driver = sql::mysql::get_driver_instance();

        /* Using the Driver to create a connection */
        con.reset(driver->connect(url, user, pass));
        con->setSchema(database);

        sql::Statement* stmt = con->createStatement();
        stmt->execute("INSERT INTO ru (store_name) values ('Test is successful')");
    } catch (sql::SQLException &e) {
        return EXIT_FAILURE;
    } catch (std::runtime_error &e) {
        return EXIT_FAILURE;
    }

    return EXIT_SUCCESS;
}

在Xcode中运行该程序后,我收到程序编译成功的消息,但在调用时停止运行:

driver->connect(url, user, pass)

给我一​​个错误

EXC_BAD_ACCESS (code=13, address=0x0)

此处描述了几乎相同的情况:here on this site

我重复了那些家伙所遵循的所有步骤,但我对这个错误无能为力。我还尝试使用以下命令在终端中编译程序:

c++ -o test -I /usr/local/boost_1_53_0 -lmysqlcppconn main.cpp

并且一切正常,但不在Xcode中。

this thread中找到了解决方案,但很抱歉我的愚蠢,我只是不知道我需要在我的Xcode中做什么才能让它以正确的方式编译程序。< / p>

Guys在那里写道,问题出现在-stdlib = libc ++标志中,Xcode用它来编译代码。那么我该怎么做才能避免这个错误呢?从Xcode编译器中删除该标志还是使用其他编译器?或者我应该只需要使用此标志重新编译MySQL Connector / C ++?

请解释我的最终解决方案。谢谢!

0 个答案:

没有答案
相关问题