mysql++ 查询在 Ubuntu 15.04 上崩溃
mysql++ query crashes on Ubuntu 15.04
这里我写了最简单的程序来重现我在 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() returns 为真。这里也是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 一起提供)并且一切正常。
这里我写了最简单的程序来重现我在 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() returns 为真。这里也是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 一起提供)并且一切正常。