MySQL Connector C ++-无效的指针 [英] MySQL Connector C++ - Invalid Pointer

查看:131
本文介绍了MySQL Connector C ++-无效的指针的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am trying to use the MySQL C++ Connector to connect to a database. I have added the libraries and the source code compiles correctly with all the necessary #include statements. The code I am using is the following:

#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");
}

该代码是直接从示例中获取的,应该可以正常工作.我已经大大缩短了代码,因为它位于引发错误的最后驱动程序->连接"行.我的错误消息如下:

The code is taken right from the examples and should work properly. I have shortened the code significantly, as it is at the final "driver -> connect" line where the error is thrown. My error message is the following:

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

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

I'm on Linux Mint Lisa, running the latest version of MySQL and using NetBeans 7.1 as an IDE. As mentioned, the code compiles correctly, and it is on this last connection line where the error occurs. Any help or recommendations for another connection mechanism would be much appreciated.

更新

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

Here is the code from the Driver class where the connection is defined

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;

...

没什么可看的...以我的愚见...

Nothing to see there... in my humble opinion...

推荐答案

我找到了针对Ubuntu 12.04的此问题的解决方案,它使我花了大约48个小时不睡觉,但是可以了.我确定此修复程序将适用于其他版本的Ubuntu. 从 http://www.sopcast.com/download/libstdcpp5.tgz下载libstdc ++.so.5 .您需要解压缩文件并将其放置在/usr/lib中.

I have found the solution to this problem for Ubuntu 12.04, it has taken me about 48 hours of no sleep but ok, here goes. Im sure this fix will work for other versions of Ubuntu. Download the libstdc++.so.5 from http://www.sopcast.com/download/libstdcpp5.tgz. You need to extract and place the files in /usr/lib.

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

Make sure you add -llibstdc++.so.5 when building your app with g++ ( this links stdc++ v5)

然后使用Google'Connector c ++ Ubuntu 12.04',寻找Builds并下载Arch的.deb.

Then Google 'Connector c++ Ubuntu 12.04' and look for the Builds and download the .deb for your Arch.

对于Ubuntu 12.04,这是.debs的URL https://launchpad.net/ubuntu/precise/+source/mysql-connector-c ++/+ builds 选择你的拱门. Amd64,然后在"Builded Files"下下载两个.debs.使用程序包管理器打开并安装.您应该现在就可以运行您的应用,而不会出现问题.

For Ubuntu 12.04 here is the URL for the .debs https://launchpad.net/ubuntu/precise/+source/mysql-connector-c++/+builds Choose your arch ie. Amd64 and download the two .debs under the Built Files. Open and install using the package manager. You should be able to run you app now without and issues.

编辑 您不需要链接libstdc ++.so.5,可能需要在系统上进行链接,但是在Ubuntu 12.04 amd64上则不需要.

EDIT You do not need to link libstdc++.so.5, you might have to on your system but on Ubuntu 12.04 amd64 its not needed.

这篇关于MySQL Connector C ++-无效的指针的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆