MySQL Connector/C++ crashes with g++8.1.0 and C++17

馋奶兔 提交于 2019-12-24 19:42:40

问题


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

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.

This is basically the program:

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

And this is the error I get in Visual studio:

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).

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

* Error in `./LSTGA.out': munmap_chunk(): invalid pointer: 0x7ec3c50c * Aborted

The call stack:

Additional information:

  • Previous compiler: gcc-4.9 / g++-4.9 (still present)
  • New compiler: gcc-8.1.0 / g++-8.1.0
  • Previous LIBSTDC++: 6.0.22 (Removed)
  • New LIBSTDC++: 6.0.25
  • Remote machine: Raspberry Pi 2b
  • Remote OS: Raspbian
  • Local OS: Windows 10
  • Visual studio Community 2017 15.8.8

Thanks in advance. -Minding


回答1:


I found the issue here:

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.

So the solution is to build the MySQL Connector/C++ from source as described here.

I hope this helps.



来源:https://stackoverflow.com/questions/53071286/mysql-connector-c-crashes-with-g8-1-0-and-c17

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!