Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cv_bridge exposes internal GTest symbols from OpenCV and/or links incorrectly #22

Closed
cmansley opened this issue Sep 4, 2013 · 10 comments

Comments

@cmansley
Copy link

cmansley commented Sep 4, 2013

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.

@vrabaud
Copy link
Contributor

vrabaud commented Sep 4, 2013

can you do an ldd on your executable ? How come it is linked against OpenCV, there is no OpenCV code in there ? I replicated your code with catkin and did not get any error.
Following your isntructions, rosmake test did not work (I guess the created package is not a proper stack).

@cmansley
Copy link
Author

cmansley commented Sep 4, 2013

Here is the output from ldd:

    linux-vdso.so.1 =>  (0x00007fff546fe000)
libopencv_ts.so.2.4 => /opt/ros/groovy/lib/libopencv_ts.so.2.4 (0x00007f331d5ee000)
libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f331d2c8000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f331d0b1000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f331ccf2000)
libopencv_core.so.2.4 => /opt/ros/groovy/lib/libopencv_core.so.2.4 (0x00007f331c8b4000)
libopencv_imgproc.so.2.4 => /opt/ros/groovy/lib/libopencv_imgproc.so.2.4 (0x00007f331c3f6000)
libopencv_highgui.so.2.4 => /opt/ros/groovy/lib/libopencv_highgui.so.2.4 (0x00007f331c0ac000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f331be8f000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f331bb92000)
/lib64/ld-linux-x86-64.so.2 (0x00007f331d8a6000)
libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007f331b97b000)
librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007f331b773000)
libjpeg.so.8 => /usr/lib/x86_64-linux-gnu/libjpeg.so.8 (0x00007f331b522000)
libpng12.so.0 => /lib/x86_64-linux-gnu/libpng12.so.0 (0x00007f331b2fa000)
libtiff.so.4 => /usr/lib/x86_64-linux-gnu/libtiff.so.4 (0x00007f331b096000)
libjasper.so.1 => /usr/lib/x86_64-linux-gnu/libjasper.so.1 (0x00007f331ae3e000)
libgtk-x11-2.0.so.0 => /usr/lib/x86_64-linux-gnu/libgtk-x11-2.0.so.0 (0x00007f331a804000)
libgdk-x11-2.0.so.0 => /usr/lib/x86_64-linux-gnu/libgdk-x11-2.0.so.0 (0x00007f331a552000)
libgobject-2.0.so.0 => /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0 (0x00007f331a302000)
libglib-2.0.so.0 => /lib/x86_64-linux-gnu/libglib-2.0.so.0 (0x00007f331a00d000)
libv4l1.so.0 => /usr/lib/x86_64-linux-gnu/libv4l1.so.0 (0x00007f3319e07000)
libavcodec.so.53 => /usr/lib/x86_64-linux-gnu/libavcodec.so.53 (0x00007f3318ff7000)
libavformat.so.53 => /usr/lib/x86_64-linux-gnu/libavformat.so.53 (0x00007f3318cf7000)
libavutil.so.51 => /usr/lib/x86_64-linux-gnu/libavutil.so.51 (0x00007f3318ad7000)
libswscale.so.2 => /usr/lib/x86_64-linux-gnu/libswscale.so.2 (0x00007f3318890000)
libpangocairo-1.0.so.0 => /usr/lib/x86_64-linux-gnu/libpangocairo-1.0.so.0 (0x00007f3318684000)
libX11.so.6 => /usr/lib/x86_64-linux-gnu/libX11.so.6 (0x00007f331834e000)
libXfixes.so.3 => /usr/lib/x86_64-linux-gnu/libXfixes.so.3 (0x00007f3318148000)
libatk-1.0.so.0 => /usr/lib/x86_64-linux-gnu/libatk-1.0.so.0 (0x00007f3317f26000)
libcairo.so.2 => /usr/lib/x86_64-linux-gnu/libcairo.so.2 (0x00007f3317c67000)
libgdk_pixbuf-2.0.so.0 => /usr/lib/x86_64-linux-gnu/libgdk_pixbuf-2.0.so.0 (0x00007f3317a47000)
libgio-2.0.so.0 => /usr/lib/x86_64-linux-gnu/libgio-2.0.so.0 (0x00007f33176f8000)
libpangoft2-1.0.so.0 => /usr/lib/x86_64-linux-gnu/libpangoft2-1.0.so.0 (0x00007f33174cd000)
libpango-1.0.so.0 => /usr/lib/x86_64-linux-gnu/libpango-1.0.so.0 (0x00007f3317284000)
libfontconfig.so.1 => /usr/lib/x86_64-linux-gnu/libfontconfig.so.1 (0x00007f331704e000)
libXext.so.6 => /usr/lib/x86_64-linux-gnu/libXext.so.6 (0x00007f3316e3c000)
libXrender.so.1 => /usr/lib/x86_64-linux-gnu/libXrender.so.1 (0x00007f3316c32000)
libXinerama.so.1 => /usr/lib/x86_64-linux-gnu/libXinerama.so.1 (0x00007f3316a2f000)
libXi.so.6 => /usr/lib/x86_64-linux-gnu/libXi.so.6 (0x00007f331681f000)
libXrandr.so.2 => /usr/lib/x86_64-linux-gnu/libXrandr.so.2 (0x00007f3316617000)
libXcursor.so.1 => /usr/lib/x86_64-linux-gnu/libXcursor.so.1 (0x00007f331640d000)
libXcomposite.so.1 => /usr/lib/x86_64-linux-gnu/libXcomposite.so.1 (0x00007f3316209000)
libXdamage.so.1 => /usr/lib/x86_64-linux-gnu/libXdamage.so.1 (0x00007f3316006000)
libffi.so.6 => /usr/lib/x86_64-linux-gnu/libffi.so.6 (0x00007f3315dfd000)
libpcre.so.3 => /lib/x86_64-linux-gnu/libpcre.so.3 (0x00007f3315bc0000)
libv4l2.so.0 => /usr/lib/x86_64-linux-gnu/libv4l2.so.0 (0x00007f33159b4000)
libvpx.so.1 => /usr/lib/libvpx.so.1 (0x00007f331570f000)
libvorbisenc.so.2 => /usr/lib/x86_64-linux-gnu/libvorbisenc.so.2 (0x00007f331523f000)
libvorbis.so.0 => /usr/lib/x86_64-linux-gnu/libvorbis.so.0 (0x00007f3315013000)
libtheoraenc.so.1 => /usr/lib/x86_64-linux-gnu/libtheoraenc.so.1 (0x00007f3314dd6000)
libtheoradec.so.1 => /usr/lib/x86_64-linux-gnu/libtheoradec.so.1 (0x00007f3314bba000)
libspeex.so.1 => /usr/lib/x86_64-linux-gnu/libspeex.so.1 (0x00007f33149a1000)
libschroedinger-1.0.so.0 => /usr/lib/libschroedinger-1.0.so.0 (0x00007f33146ee000)
libgsm.so.1 => /usr/lib/libgsm.so.1 (0x00007f33144df000)
libva.so.1 => /usr/lib/x86_64-linux-gnu/libva.so.1 (0x00007f33142c9000)
libbz2.so.1.0 => /lib/x86_64-linux-gnu/libbz2.so.1.0 (0x00007f33140b9000)
libfreetype.so.6 => /usr/lib/x86_64-linux-gnu/libfreetype.so.6 (0x00007f3313e1c000)
libxcb.so.1 => /usr/lib/x86_64-linux-gnu/libxcb.so.1 (0x00007f3313bfe000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f33139f9000)
libpixman-1.so.0 => /usr/lib/x86_64-linux-gnu/libpixman-1.so.0 (0x00007f3313772000)
libxcb-shm.so.0 => /usr/lib/x86_64-linux-gnu/libxcb-shm.so.0 (0x00007f331356f000)
libxcb-render.so.0 => /usr/lib/x86_64-linux-gnu/libxcb-render.so.0 (0x00007f3313364000)
libgmodule-2.0.so.0 => /usr/lib/x86_64-linux-gnu/libgmodule-2.0.so.0 (0x00007f3313160000)
libselinux.so.1 => /lib/x86_64-linux-gnu/libselinux.so.1 (0x00007f3312f40000)
libresolv.so.2 => /lib/x86_64-linux-gnu/libresolv.so.2 (0x00007f3312d24000)
libexpat.so.1 => /lib/x86_64-linux-gnu/libexpat.so.1 (0x00007f3312af9000)
libv4lconvert.so.0 => /usr/lib/x86_64-linux-gnu/libv4lconvert.so.0 (0x00007f3312884000)
libogg.so.0 => /usr/lib/x86_64-linux-gnu/libogg.so.0 (0x00007f331267d000)
liborc-0.4.so.0 => /usr/lib/x86_64-linux-gnu/liborc-0.4.so.0 (0x00007f3312401000)
libXau.so.6 => /usr/lib/x86_64-linux-gnu/libXau.so.6 (0x00007f33121fe000)
libXdmcp.so.6 => /usr/lib/x86_64-linux-gnu/libXdmcp.so.6 (0x00007f3311ff8000)

@cmansley
Copy link
Author

cmansley commented Sep 4, 2013

To be clear, I am using groovy on Ubuntu 12.04

@vrabaud
Copy link
Contributor

vrabaud commented Sep 4, 2013

wow, that is crazy. What is your gcc version ? Also, did you get the rosmake test call to work ? Or did you have to add astack.yaml or something ?

@cmansley
Copy link
Author

cmansley commented Sep 4, 2013

gcc (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3
Copyright (C) 2011 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

And rosmake test work just fine except that it crashes. And the only other thing I had to do to make this function was add the directory to my ros package path. That is it. Nothing else.

@cmansley
Copy link
Author

cmansley commented Sep 4, 2013

Again to clarify, it compiles the test correctly. The test itself crashes.

@cmansley
Copy link
Author

cmansley commented Sep 4, 2013

The problem here is that opencv_ts includes the gtest symbols, because someone at opencv included gtest in the library. So, the test links to opencv.

@vrabaud
Copy link
Contributor

vrabaud commented Sep 8, 2013

Ok, was able to replicate it.
@dirk-thomas , have we faced that we other packages ? It can be solved if the gtest libraries appear before the opencv ones in the linkage. Can the rosbuild macro be modified for that ? Thx.

@cmansley
Copy link
Author

cmansley commented Sep 9, 2013

I am not a catkin expert, but I think the real problem is in the cv_bridge CMakeLists.txt file on line 20. It adds the entire opencv library directory to the link path:
link_directories(${OpenCV_LIB_DIR})
but in the src\CMakeLists.txt, the libraries are included "correctly"
target_link_libraries(${PROJECT_NAME} ${OpenCV_LIBRARIES} ${catkin_LIBRARIES})

I don't see the purpose of adding the entire opencv library path, when you should only include the libraries as returned by the find_package command in the OpenCV_LIBRARIES variable.

The FindOpenCV.cmake correctly does not export the ts library, which is where the conflicting symbols are.

@vrabaud vrabaud closed this as completed in 445d597 Sep 9, 2013
@vrabaud
Copy link
Contributor

vrabaud commented Sep 9, 2013

cool, that worked for me, thx. I did not think that could impact the exported tag but that makes sense. Releasing now.

luca-della-vedova pushed a commit to luca-della-vedova/vision_opencv that referenced this issue Sep 2, 2020
…ints_catkin_fix

Fix roslib import for message module, remove roslib.load_manifest
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants