这里我编写了最简单的程序来重现我在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)
答案 0 :(得分:1)
我在发生崩溃的系统中将g ++从4.9.2更新到5.1.1。由于某种原因,后来编译器编译的代码与mysql库不兼容(显然由4.9.2编译器编译)。我将编译器恢复到4.9.2(最初是ubuntu 15.04),一切都运行良好。