Using gtest with cv_bridge fails
If we create a package as follows:
$ roscreate-pkg opencv_tests roscpp cv_bridge
$ cd opencv_tests
$ mkdir test
$ echo "rosbuild_add_gtest(test_opencv test/test_opencv.cpp)" >> CMakeLists.txt
and test_opencv.cpp
contains
#include <gtest/gtest.h>
int main(int argc, char **argv)
{
testing::InitGoogleTest(&argc, argv);
::testing::FLAGS_gtest_death_test_style = "threadsafe";
return RUN_ALL_TESTS();
}
then we run rosmake test
, the test compiles, but crashes on destruction.
Here is the gdb output:
(gdb) bt
#0 0x00007ffff7285425 in __GI_raise (sig=<optimized out>) at ../nptl/sysdeps/unix/sysv/linux/raise.c:64
#1 0x00007ffff7288b8b in __GI_abort () at abort.c:91
#2 0x00007ffff72c339e in __libc_message (do_abort=2, fmt=0x7ffff73cd008 "*** glibc detected *** %s: %s: 0x%s ***\n") at ../sysdeps/unix/sysv/linux/libc_fatal.c:201
#3 0x00007ffff72cdb96 in malloc_printerr (action=3, str=0x7ffff73c9913 "free(): invalid pointer", ptr=<optimized out>) at malloc.c:5018
#4 0x0000000000400b67 in operator= (rhs=..., this=<optimized out>) at /usr/include/gtest/internal/gtest-string.h:285
#5 operator= (a_c_str=0x400e4c "threadsafe", this=<optimized out>) at /usr/include/gtest/internal/gtest-string.h:279
#6 main (argc=1, argv=<optimized out>) at /home/user/opencv_tests/test/test_opencv.cpp:7
(gdb)
When I get this error, it typically is because GTest and OpenCV are fighting about symbols. In other words, OpenCV includes a version of GTest and we are linking against the wrong one.
Asked by cmansley on 2013-09-04 11:39:48 UTC
Comments