MySQL 连接器 C++ - 无效指针

2024-03-27

我正在尝试使用 MySQL C++ 连接器连接到数据库。我已经添加了库,并且源代码可以使用所有必要的 #include 语句正确编译。我正在使用的代码如下:

#include <stdlib.h>
#include <iostream>

#include "mysql_connection.h"

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

using namespace std;

int main(void)
{
    using namespace sql;

    Driver *driver;
    Connection *con;

driver = get_driver_instance();
con = driver -> connect("tcp://127.0.0.1:3306/test", "test", "test");
}

该代码直接取自示例,应该可以正常工作。我显着缩短了代码,因为它位于抛出错误的最后“driver -> connect”行。我的错误消息如下:

*** glibc detected *** /home/username/NetBeansProjects/mysql/dist/Release/GNU-Linux-x86/mysql:
free(): invalid pointer: 0x091dd468 ***

我使用 Linux Mint Lisa,运行最新版本的 MySQL 并使用 NetBeans 7.1 作为 IDE。如前所述,代码编译正确,并且错误发生在最后一条连接线上。对于其他连接机制的任何帮助或建议将不胜感激。


UPDATE

这是定义连接的 Driver 类的代码

class CPPCONN_PUBLIC_FUNC Driver
{
protected:
virtual ~Driver() {}
public:
// Attempts to make a database connection to the given URL.

virtual Connection * connect(const sql::SQLString& hostName, const sql::SQLString& userName, const sql::SQLString& password) = 0;

virtual Connection * connect(ConnectOptionsMap & options) = 0;

...

那里没什么可看的……以我的愚见……


我已经在 Ubuntu 12.04 上找到了这个问题的解决方案,我花了大约 48 个小时没有睡觉,但是好吧,就这样。我确信此修复程序适用于其他版本的 Ubuntu。 从以下位置下载 libstdc++.so.5http://www.sopcast.com/download/libstdcpp5.tgz http://www.sopcast.com/download/libstdcpp5.tgz。您需要提取文件并将其放置在 /usr/lib 中。

确保在使用 g++ 构建应用程序时添加 -libstdc++.so.5 (这链接了 stdc++ v5)

然后 Google“Connector c++ Ubuntu 12.04”并查找 Builds 并下载适用于您的 Arch 的 .deb。

对于 Ubuntu 12.04,这里是 .debs 的 URLhttps://launchpad.net/ubuntu/precise/+source/mysql-connector-c++/+builds https://launchpad.net/ubuntu/precise/+source/mysql-connector-c++/+builds选择你的拱门。 Amd64 并下载内置文件下的两个 .deb 文件。使用包管理器打开并安装。您现在应该能够运行您的应用程序而不会出现问题。

EDIT您不需要链接 libstdc++.so.5,您可能必须在您的系统上链接,但在 Ubuntu 12.04 amd64 上不需要链接。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

MySQL 连接器 C++ - 无效指针 的相关文章

随机推荐