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 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 00:00 0
b711e000-b7122000 r-xp 00000000 08:06 655094 /lib/i386-linux-gnu/libuuid.so.1.3.0
b7122000-b7123000 r--p 00003000 08:06 655094 /lib/i386-linux-gnu/libuuid.so.1.3.0
b7123000-b7124000 rw-p 00004000 08:06 655094 /lib/i386-linux-gnu/libuuid.so.1.3.0
b7124000-b714a000 r-xp 00000000 08:06 655031 /lib/i386-linux-gnu/libexpat.so.1.5.2
b714a000-b714b000 ---p 00026000 08:06 655031 /lib/i386-linux-gnu/libexpat.so.1.5.2
b714b000-b714d000 r--p 00026000 08:06 655031 /lib/i386-linux-gnu/libexpat.so.1.5.2
b714d000-b714e000 rw-p 00028000 08:06 655031 /lib/i386-linux-gnu/libexpat.so.1.5.2
b714e000-b730a000 r-xp 00000000 08:06 821139 /usr/lib/libicui18n.so.44.2
b730a000-b7310000 r--p 001bb000 08:06 821139 /usr/lib/libicui18n.so.44.2
b7310000-b7311000 rw-p 001c1000 08:06 821139 /usr/lib/libicui18n.so.44.2
b7311000-b7312000 rw-p 00000000 00:00 0
b7312000-b7446000 r-xp 00000000 08:06 821145 /usr/lib/libicuuc.so.44.2
b7446000-b744f000 r--p 00133000 08:06 821145 /usr/lib/libicuuc.so.44.2
b744f000-b7450000 rw-p 0013c000 08:06 821145 /usr/lib/libicuuc.so.44.2
b7450000-b7454000 rw-p 00000000 00:00 0
b7454000-b7487000 r-xp 00000000 08:06 820556 /usr/lib/libapr-1.so.0.4.5
b7487000-b7488000 r--p 00032000 08:06 820556 /usr/lib/libapr-1.so.0.4.5
b7488000-b7489000 rw-p 00033000 08:06 820556 /usr/lib/libapr-1.so.0.4.5
b7489000-b748a000 rw-p 00000000 00:00 0
b748a000-b74ab000 r-xp 00000000 08:06 820566 /usr/lib/libaprutil-1.so.0.3.12
b74ab000-b74ac000 r--p 00020000 08:06 820566 /usr/lib/libaprutil-1.so.0.3.12
b74ac000-b74ad000 rw-p 00021000 08:06 820566 /usr/lib/libaprutil-1.so.0.3.12
b74ad000-b759a000 r-xp 00000000 08:06 791769 /usr/lib/libboost_regex.so.1.46.1
b759a000-b759b000 ---p 000ed000 08:06 791769 /usr/lib/libboost_regex.so.1.46.1
b759b000-b759e000 r--p 000ed000 08:06 791769 /usr/lib/libboost_regex.so.1.46.1
b759e000-b759f000 rw-p 000f0000 08:06 791769 /usr/lib/libboost_regex.so.1.46.1
b759f000-b75a0000 rw-p 00000000 00:00 0
b75a0000-b75a7000 r-xp 00000000 08:06 655079 /lib/i386-linux-gnu/librt-2.13.so
b75a7000-b75a8000 r--p 00006000 08:06 655079 /lib/i386-linux-gnu/librt-2.13.so
b75a8000-b75a9000 rw-p 00007000 08:06 655079 /lib/i386-linux-gnu/librt-2.13.so
b75a9000-b7659000 r-xp 00000000 08:06 828163 /usr/lib/i386-linux-gnu/libstdc++.so.5.0.7
b7659000-b765e000 rw-p 000af000 08:06 828163 /usr/lib/i386-linux-gnu/libstdc++.so.5.0.7
b765e000-b7663000 rw-p 00000000 00:00 0
b7663000-b7678000 r-xp 00000000 08:06 655050 /lib/i386-linux-gnu/libnsl-2.13.so
b7678000-b7679000 r--p 00015000 08:06 655050 /lib/i386-linux-gnu/libnsl-2.13.so
b7679000-b767a000 rw-p 00016000 08:06 655050 /lib/i386-linux-gnu/libnsl-2.13.so
b767a000-b767d000 rw-p 00000000 00:00 0
b767d000-b7685000 r-xp 00000000 08:06 655021 /lib/i386-linux-gnu/libcrypt-2.13.so
b7685000-b7686000 r--p 00007000 08:06 655021 /lib/i386-linux-gnu/libcrypt-2.13.so
b7686000-b7687000 rw-p 00008000 08:06 655021 /lib/i386-linux-gnu/libcrypt-2.13.so
b7687000-b76ae000 rw-p 00000000 00:00 0
b76ae000-b76d6000 r-xp 00000000 08:06 655045 /lib/i386-linux-gnu/libm-2.13.so
b76d6000-b76d7000 r--p 00028000 08:06 655045 /lib/i386-linux-gnu/libm-2.13.so
b76d7000-b76d8000 rw-p 00029000 08:06 655045 /lib/i386-linux-gnu/libm-2.13.so
b76d8000-b76ef000 r-xp 00000000 08:06 655075 /lib/i386-linux-gnu/libpthread-2.13.so
b76ef000-b76f0000 r--p 00016000 08:06 655075 /lib/i386-linux-gnu/libpthread-2.13.so
b76f0000-b76f1000 rw-p 00017000 08:06 655075 /lib/i386-linux-gnu/libpthread-2.13.so
b76f1000-b76f3000 rw-p 00000000 00:00 0
b76f3000-b7708000 r-xp 00000000 08:06 821924 /usr/lib/libboost_thread.so.1.46.1
b7708000-b7709000 ---p 00015000 08:06 821924 /usr/lib/libboost_thread.so.1.46.1
b7709000-b770a000 r--p 00015000 08:06 821924 /usr/lib/libboost_thread.so.1.46.1
b770a000-b770b000 rw-p 00016000 08:06 821924 /usr/lib/libboost_thread.so.1.46.1
b770b000-b7893000 r-xp 00000000 08:06 822384 /usr/lib/liblog4cxx.so.10.0.0
b7893000-b78a9000 r--p 00187000 08:06 822384 /usr/lib/liblog4cxx.so.10.0.0
b78a9000-b78aa000 rw-p 0019d000 08:06 822384 /usr/lib/liblog4cxx.so.10.0.0
b78aa000-b78ac000 rw-p 00000000 00:00 0
b78ac000-b78ae000 r-xp 00000000 08:06 821004 /usr/lib/libboost_system.so.1.46.1
b78ae000-b78af000 r--p 00002000 08:06 821004 /usr/lib/libboost_system.so.1.46.1
b78af000-b78b0000 rw-p 00003000 08:06 821004 /usr/lib/libboost_system.so.1.46.1
b78b0000-b78cc000 r-xp 00000000 08:06 821005 /usr/lib/libboost_filesystem.so.1.46.1
b78cc000-b78cd000 r--p 0001b000 08:06 821005 /usr/lib/libboost_filesystem.so.1.46.1
b78cd000-b78ce000 rw-p 0001c000 08:06 821005 /usr/lib/libboost_filesystem.so.1.46.1
Originally posted by ads on ROS Answers with karma: 16 on 2012-05-18
Post score: 0
Original comments
Comment by dornhege on 2012-05-18:
The export tags are not needed. They are only if someone else uses a library that your package exposes.
Comment by ads on 2012-05-18:
Thanks for your input dornhege. I removed the export flags, however the problem still remains :(
Comment by Lorenz on 2012-05-18:
Try running in gdb to find out which call exactly causes the error. It might be interesting to see a backtrace.
Comment by ads on 2012-05-18:
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.
Comment by ads on 2012-05-18:
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
Comment by ads on 2012-05-18:
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?