MySQL and ROS
Hi
I have been trying to add MySQL to my ROS-project and I can compile, link and execute each succesfully separately, but when I combine ROS and calls to MySQL they will still compile and link, but when I run the executable the program gives the following error:
*** glibc detected *** ./DatabaseConnection: free(): invalid pointer: 0x088cf1e8 ***
When I insert the ros::init
call in the following code, the invalid pointer problem happens. The problem i basically when I call mysql_init()
in DatabaseConnection
.
int main(int argc, char **argv)
{
ros::init(argc, argv, "Database");
DatabaseConnection *databaseConnection = new DatabaseConnection();
databaseConnection->call();
return 0;
}
I have followed the steps described http://answers.ros.org/question/32520/add-mysql-to-a-ros-project">here with no luck.
I have added the following to my manifest.xml but I'm not sure if I need to add additional linker flags or what the problem is:
<rosdep name="libmysqlclient-dev"/>
<export>
<cpp lflags="-lmysqlclient"/>
</export>
This is the relevant part of my CMakeLists.txt
:
rosbuild_add_executable(DatabaseConnection src/DatabaseConnection.cpp)
target_link_libraries(DatabaseConnection libmysqlcppconn.so)
What am I missing? Any help is much appreciated. Thanks.
EDIT: Included stack from GDB and a backtrace. It seems that it simply dies immediately. I can't really step through the program.
Stack:
DatabaseConnection [C/C++ Application]
/home/adz/ros_workspace/HRIManager/bin/DatabaseConnection [2548] [cores: 0]
Thread [1] 2548 [core: 0] (Suspended : Signal : SIGABRT:Aborted)
__kernel_vsyscall() at 0xb7fdf424
raise() at 0xb7983c8f
abort() at 0xb79872b5
0xb79b9dfc
0xb79c4bc2
0xb79c5862
free() at 0xb79c894d
operator delete() at 0xb7b9d80f
std::string::_Rep::_M_destroy() at 0xb7b84c4b
log4cxx::helpers::Class::registerClass() at 0xb77b1303
log4cxx::helpers::ClassRegistration::ClassRegistration() at 0xb77b376b
log4cxx::helpers::AppenderAttachableImpl::registerClass() at 0xb77a2b04
0xb77a0914
0xb7fee81b
0xb7fee904
0xb7fe111f
gdb
Backtrace:
*** glibc detected *** /home/adz/ros_workspace/HRIManager/bin/DatabaseConnection: free(): invalid pointer: 0x0804c1e8 ***
======= Backtrace: =========
/lib/i386-linux-gnu/libc.so.6(+0x6ebc2)[0xb79c4bc2]
/lib/i386-linux-gnu/libc.so.6(+0x6f862)[0xb79c5862]
/lib/i386-linux-gnu/libc.so.6(cfree+0x6d)[0xb79c894d]
/usr/lib/i386-linux-gnu/libstdc++.so.6(_ZdlPv+0x1f)[0xb7b9d80f]
/usr/lib/i386-linux-gnu/libstdc++.so.6(_ZNSs4_Rep10_M_destroyERKSaIcE+0x1b)[0xb7b84c4b]
/usr/lib/liblog4cxx.so.10(_ZN7log4cxx7helpers5Class13registerClassERKS1_+0x1f3)[0xb77b1303]
/usr/lib/liblog4cxx.so.10(_ZN7log4cxx7helpers17ClassRegistrationC2EPFRKNS0_5ClassEvE+0x1b)[0xb77b376b]
/usr/lib/liblog4cxx.so.10(_ZN7log4cxx7helpers22AppenderAttachableImpl13registerClassEv+0x64)[0xb77a2b04]
/usr/lib/liblog4cxx.so.10(+0x95914)[0xb77a0914]
/lib/ld-linux.so.2(+0xe81b)[0xb7fee81b]
/lib/ld-linux.so.2(+0xe904)[0xb7fee904]
/lib/ld-linux.so.2(+0x111f)[0xb7fe111f]
======= Memory map: ========
08048000-0804a000 r-xp 00000000 08:06 665000 /home/adz/ros_workspace/HRIManager/bin/DatabaseConnection
0804a000-0804b000 r--p 00001000 08:06 665000 /home/adz/ros_workspace/HRIManager/bin/DatabaseConnection
0804b000-0804c000 rw-p 00002000 08:06 665000 /home/adz/ros_workspace/HRIManager/bin/DatabaseConnection
0804c000-0806d000 rw-p 00000000 00:00 0 [heap]
b6100000-b6121000 rw-p 00000000 00:00 0
b6121000-b6200000 ---p 00000000 00:00 0
b62d0000-b62d7000 rw-p 00000000 00:00 0
b62d7000-b7117000 r--p 00000000 08:06 821143 /usr/lib/libicudata.so.44.2
b7117000-b7118000 rw-p 00e3f000 08:06 821143 /usr/lib/libicudata.so.44.2
b7118000-b711b000 r-xp 00000000 08:06 655026 /lib/i386-linux-gnu/libdl-2.13.so
b711b000-b711c000 r--p 00002000 08:06 655026 /lib/i386-linux-gnu/libdl-2.13.so
b711c000-b711d000 rw-p 00003000 08:06 655026 /lib/i386-linux-gnu/libdl-2.13.so
b711d000-b711e000 rw-p 00000000 ...
The export tags are not needed. They are only if someone else uses a library that your package exposes.
Thanks for your input dornhege. I removed the export flags, however the problem still remains :(
Try running in gdb to find out which call exactly causes the error. It might be interesting to see a backtrace.
Lorenz, I added the stack from gdb and a backtrace. It seems that the program dies immediately and I am not able to step through it.
I just noticed that /usr/lib/i386-linux-gnu/libstdc++.so.6 is in the backtrace. I am running libstdc++.so.5 and I remember the linker warning me: /usr/bin/ld: warning: libstdc++.so.5, needed by /usr/lib/gcc/i686-linux-gnu/4.6.1/../../../../lib/libmysqlcppconn.so, may conflict with libstdc++.so.6
Maybe libstdc++ could be cause the problem, but libstdc++.so.5 is needed by the mysql c++ connector. Could the solution be to upgrade to libstdc++.so.6?