MySQL Connector/C ++在g ++ 8.1.0和C ++ 17下崩溃 [英] MySQL Connector/C++ crashes with g++8.1.0 and C++17

查看:194
本文介绍了MySQL Connector/C ++在g ++ 8.1.0和C ++ 17下崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚开始使用Visual Studio 2017在C ++中进行编程,并连接到我的数据库.到目前为止,一切工作正常.然后我想使用c ++ 17功能并意识到我需要升级我的编译器.

I just started programming in C++ using Visual Studio 2017 and connected to my database. Everything worked fine so far. Then I wanted to use a c++17 feature and realized I needed to upgrade my compiler.

使用

After upgrading my compiler to g++8.1.0 using this blog with these commands (and a lot of trial and error):

git clone https://bitbucket.org/sol_prog/raspberry-pi-gcc-binary.git
cd raspberry-pi-gcc-binary
tar xf gcc-8.1.0.tar.bz2
mv gcc-8.1.0 /usr/bin
cd ..
rm -r raspberry-pi-gcc-binary
rm /usr/bin/gcc
rm /usr/bin/g++
ln -s /usr/bin/gcc-8.1.0/bin/gcc-8.1.0 /usr/bin/gcc
ln -s /usr/bin/gcc-8.1.0/bin/g++-8.1.0 /usr/bin/g++

 # After getting the error "GLIBCXX_3.4.21 not found" I did the following:
rm /usr/lib/arm-linux-gnueabihf/libstdc++.so.6
 # I don't know if this (next line) was necessary
rm /usr/lib/arm-linux-gnueabihf/libstdc++.so.6.0.22
ln -s /usr/bin/gcc-8.1.0/lib/libstdc++.so.6.0.25 /usr/lib/arm-linux-gnueabihf/libstdc++.so.6

现在程序可以编译了,但是当我执行它时,它崩溃了.当我切换到旧的编译器(g ++-4.9)时,它将再次起作用.也许新的编译器没有正确安装.有关如何在Raspbian上安装GCC-8的说明非常有用.

Now the program compiles, but when I excecute it, it crashes. When I switch to the old compiler (g++-4.9) it works again. Maybe the new compiler isn't properly installed. Instructions on how to install GCC-8 on Raspbian would be great.

这基本上是程序:

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

#include<mysql_driver.h> //OR #include<cppconn/driver.h>
#include<mysql_connection.h> //OR #include<cppconn/connection.h>

sql::mysql::MySQL_Driver* driver; //OR sql::Driver*
sql::Connection* conn;

int main(const int argc, const char* argv[]) {
  try {
        driver = sql::mysql::get_driver_instance(); //OR get_driver_instance();
        conn = driver->connect("tcp://127.0.0.1:3306", "root", "MY_PW");
        conn->setSchema("MY_DB");
    } catch (std::exception &e) {
        //err("Failed to connect to the database.", e);
    }
}

这是我在Visual Studio中遇到的错误:

And this is the error I get in Visual studio:

中止(gdb)1055-var-create-*"__size"(gdb) 1066-堆栈选择帧16(gdb)1067-var-create-*"argc"线程 'LSTGA.out'(0x5cfa)已退出,代码为0(0x0).程序``有 退出,代码为0(0x0).

Aborted (gdb) 1055-var-create - * "__size" (gdb) 1066-stack-select-frame 16 (gdb) 1067-var-create - * "argc" The thread 'LSTGA.out' (0x5cfa) has exited with code 0 (0x0). The program '' has exited with code 0 (0x0).

这是我直接通过SSH运行它时遇到的错误:

And this is the error I get when running it directly via SSH:

*`./LSTGA.out'中的错误:munmap_chunk():无效的指针:0x7ec3c50c * 中止

调用堆栈:

其他信息:

  • 以前的编译器:gcc-4.9/g ++-4.9(仍然存在)
  • 新编译器:gcc-8.1.0/g ++-8.1.0
  • 以前的LIBSTDC ++:6.0.22(已删除)
  • 新LIBSTDC ++:6.0.25
  • 远程机器:Raspberry Pi 2b
  • 远程操作系统:Raspbian
  • 本地操作系统:Windows 10
  • Visual Studio Community 2017 15.8.8

先谢谢了. -思维

推荐答案

我发现了问题

即使编译器版本进行很小的更改也会引起问题.如果您获得怀疑与二进制不兼容有关的错误消息,请使用用于构建和链接应用程序的相同编译器和链接器从源代码构建连接器/C ++.

Even a small change in the compiler version can cause problems. If you obtain error messages that you suspect are related to binary incompatibilities, build Connector/C++ from source, using the same compiler and linker that you use to build and link your application.

因此解决方案是按照我希望这会有所帮助.

这篇关于MySQL Connector/C ++在g ++ 8.1.0和C ++ 17下崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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