gpt4 book ai didi

mysql++ 查询在 Ubuntu 15.04 上崩溃

转载 作者:行者123 更新时间:2023-11-29 11:57:56 24 4
gpt4 key购买 nike

在这里,我编写了最简单的程序来重现 mysqlpp::Connection::query() 内的崩溃:

#include <mysql++.h>

int main(int argc, char* argv[])
{
mysqlpp::Connection conn(false);
if (conn.connect("neutrino", "localhost", "root", "1"))
{
mysqlpp::Query query = conn.query("select 1;");
}

return 0;
}

这是我的 CMakeLists.txt:

cmake_minimum_required (VERSION 3.2)
project (mysqlpptest)

add_executable(mysqlpptest main.cpp)

target_include_directories(mysqlpptest
PRIVATE
/usr/include/mysql
/usr/include/mysql++
)

target_link_libraries(mysqlpptest
-lmysqlclient
-lmysqlpp
)

一切都编译和链接良好,但 query() 由于段错误而崩溃。

数据库已创建,因此 connect() 返回 true。这里也是mysql终端测试:

glaz@glaz-linux:~$ mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 190
Server version: 5.6.25-0ubuntu0.15.04.1 (Ubuntu)

Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> use neutrino;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> select 1;
+---+
| 1 |
+---+
| 1 |
+---+
1 row in set (0,00 sec)

有什么想法可以在哪里挖掘崩溃吗?

更新:调用堆栈没有用,因为库没有调试信息:

?? ()
std::istreambuf_iterator<char, std::char_traits<char> > std::num_get<char, std::istreambuf_iterator<char, std::char_traits<char> > >::_M_extract_int<unsigned short>(std::istreambuf_iterator<char, std::char_traits<char> >, std::istreambuf_iterator<char, std::char_traits<char> >, std::ios_base&, std::_Ios_Iostate&, unsigned short&) const ()
std::num_get<char, std::istreambuf_iterator<char, std::char_traits<char> > >::do_get(std::istreambuf_iterator<char, std::char_traits<char> >, std::istreambuf_iterator<char, std::char_traits<char> >, std::ios_base&, std::_Ios_Iostate&, unsigned short&) const ()
std::ostream::seekp(long, std::_Ios_Seekdir) ()
mysqlpp::Query::Query(mysqlpp::Connection*, bool, char const*) ()
mysqlpp::Connection::query(char const*) ()
main (argc=1, argv=0x7fffffffded8)

最佳答案

我在发生崩溃的系统上将 g++ 从 4.9.2 更新到了 5.1.1。并且由于某种原因,后来的编译器编译的代码与mysql库不兼容(显然是4.9.2编译器编译的)。我将编译器恢复到 4.9.2(最初随 ubuntu 15.04 一起提供),一切都运行良好。

关于mysql++ 查询在 Ubuntu 15.04 上崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32894633/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com