Using gtest with cv_bridge fails [closed]

asked 2013-09-04 11:39:48 -0500

updated 2013-11-18 18:53:28 -0500

tfoote gravatar image

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

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.

edit retag flag offensive reopen merge delete

Closed for the following reason question is not relevant or outdated by tfoote
close date 2016-08-08 01:39:37.455336