Skip to content
This repository has been archived by the owner on Feb 11, 2022. It is now read-only.

Why does this package need opencv3-opt? #6

Closed
jwhendy opened this issue Jan 8, 2020 · 11 comments
Closed

Why does this package need opencv3-opt? #6

jwhendy opened this issue Jan 8, 2020 · 11 comments

Comments

@jwhendy
Copy link
Contributor

jwhendy commented Jan 8, 2020

$ pacman -Qi opencv
Name            : opencv
Version         : 4.2.0-1
Required By     : ros-melodic-image-geometry

$ pacman -Qi opencv3-opt
Name            : opencv3-opt
Version         : 3.4.7-2
Required By     : ros-melodic-cv-bridge

I'm trying to build a colleague's code and get errors like this:

Errors     << foo:make /home/jwhendy/catkin_ws/logs/foo/build.make.012.log                                                                                                
/usr/bin/ld: CMakeFiles/foo.cpp.o: in function `foo::foo::foo()':
foo.cpp:(.text+0x2592): undefined reference to `cv::namedWindow(cv::String const&, int)'
/usr/bin/ld: foo.cpp:(.text+0x25d7): undefined reference to `cv::setWindowProperty(cv::String const&, int, double)'
/usr/bin/ld: foo.cpp:(.text+0x2711): undefined reference to `cv::imshow(cv::String const&, cv::_InputArray const&)'
/usr/bin/ld: foo.cpp:(.text+0x2bde): undefined reference to `cv::imshow(cv::String const&, cv::_InputArray const&)'
/usr/bin/ld: foo.cpp:(.text+0x2f76): undefined reference to `cv::destroyWindow(cv::String const&)'
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/foo.dir/build.make:242: /home/jwhendy/catkin_ws/devel/.private/foo/lib/foo] Error 1
make[1]: *** [CMakeFiles/Makefile2:1425: CMakeFiles/foo.dir/all] Error 2
make: *** [Makefile:141: all] Error 2

The closest I got was this ROS Answers post. One suggestion was to rearrange some stuff in CMakeLists.txt which didn't help. Another was to compile with -DWITH_OPENCL=OFF which I tried and didn't work. Nothing has changed the error.

The only other thing that stuck out to me was I wondered if my colleague used a different opencv version. I found this post about ld errors and in running this line, I found the results interesting:

$ pkg-config --cflags --libs opencv
Package opencv was not found in the pkg-config search path.
Perhaps you should add the directory containing `opencv.pc'
to the PKG_CONFIG_PATH environment variable
Package 'opencv', required by 'virtual:world', not found

$ PKG_CONFIG_PATH=/opt/opencv3/lib/pkgconfig pkg-config --cflags --libs opencv
-I/opt/opencv3/include/opencv -I/opt/opencv3/include -L/opt/opencv3/lib -lopencv_stitching -lopencv_superres -lopencv_videostab -lopencv_aruco -lopencv_bgsegm -lopencv_bioinspired -lopencv_ccalib -lopencv_dnn_objdetect -lopencv_dpm -lopencv_face -lopencv_freetype -lopencv_fuzzy -lopencv_hdf -lopencv_hfs -lopencv_img_hash -lopencv_line_descriptor -lopencv_optflow -lopencv_reg -lopencv_rgbd -lopencv_saliency -lopencv_stereo -lopencv_structured_light -lopencv_viz -lopencv_phase_unwrapping -lopencv_surface_matching -lopencv_tracking -lopencv_datasets -lopencv_text -lopencv_highgui -lopencv_videoio -lopencv_dnn -lopencv_plot -lopencv_xfeatures2d -lopencv_shape -lopencv_video -lopencv_ml -lopencv_ximgproc -lopencv_xobjdetect -lopencv_objdetect -lopencv_calib3d -lopencv_imgcodecs -lopencv_features2d -lopencv_flann -lopencv_xphoto -lopencv_photo -lopencv_imgproc -lopencv_core

Maybe this is due to running things on the cli from scratch vs. expecting that ROS packages will populate said PKG_CONFIG_PATH, but I still found it worth mentioning. Maybe the issue is in my catkin workspace?

In any case, this brought up the broader question: why are we mixing opencv versions within ros-melodic. This seems like a bad idea in my opinion.

@jwhendy
Copy link
Contributor Author

jwhendy commented Jan 8, 2020

This ultimately fixed my issue:

target_link_libraries(
  ${OpenCV_LIBS}
  /opt/opencv3/lib/libopencv_highgui.so
  ${catkin_LIBRARIES}
 )

This does support my theory that at least something is awry with this install. It might be an opencv3 issue, but I don't know how to track down what, exactly, is wrong. I just know that OpenCV_LIBS is not appearing to work. I'm wondering if it's linking to opencv vs. opencv3-opt stuff and getting confused.


edit: I figured out which library to link directly by grep-ing for the erroring functions, which all happened to come from libopencv_highgui.so.

@jwhendy
Copy link
Contributor Author

jwhendy commented Jan 8, 2020

Further detail. This is the include line in my colleague's file:

#include <opencv2/highgui.hpp>

I know almost zilch about cpp, includs, ld, etc. so I'm having a hard time figuring out how to see why this path doesn't work.

$ locate highgui
/opt/opencv3/include/opencv/highgui.h
/opt/opencv3/include/opencv2/highgui
/opt/opencv3/include/opencv2/highgui.hpp
/opt/opencv3/include/opencv2/highgui/highgui.hpp
/opt/opencv3/include/opencv2/highgui/highgui_c.h
/opt/opencv3/lib/libopencv_highgui.so
/opt/opencv3/lib/libopencv_highgui.so.3.4
/opt/opencv3/lib/libopencv_highgui.so.3.4.7
/usr/include/boost/compute/interop/opencv/highgui.hpp
/usr/include/opencv4/opencv2/highgui
/usr/include/opencv4/opencv2/highgui.hpp
/usr/include/opencv4/opencv2/highgui/highgui.hpp
/usr/include/opencv4/opencv2/highgui/highgui_c.h
/usr/lib/libopencv_highgui.so
/usr/lib/libopencv_highgui.so.4.2
/usr/lib/libopencv_highgui.so.4.2.0

So maybe back to the original theory: the .hpp is found for one version of opencv, but the linker is looking for the corresponding libopencv_highgui.so for a different version of opencv?

@acxz
Copy link
Member

acxz commented Jan 8, 2020

Just gonna drop the upstream issue here: ros-perception/vision_opencv#272

@jwhendy
Copy link
Contributor Author

jwhendy commented Jan 8, 2020

Nice. That may help, though we also may have an issue with a fully functioning ros-melodic ecosystem. My current questions:

  • any input into how to understand exactly what's going on above? Mainly why is including OpenCV_LIBS insufficient and I have to point directly to the .so itself?
  • if this is related to using both opencv3 and opencv4, what is the right solution?
  • edited to add: is it troublesome to anyone else that the pkg-config command doesn't work as-is, and one needs to do PKG_CONFIG_PATH=/opt/opencv... for this to work?

@acxz
Copy link
Member

acxz commented Jan 8, 2020

I'm afraid I do not have the time to pry into the issues you have been facing.

The right solution I think is to use the latest opencv.

@jwhendy
Copy link
Contributor Author

jwhendy commented Jan 8, 2020

Completely understood. I'll leave this open as I think it's one thing to compile the package successfully, but another if there's something odd in our setup that doesn't let users actually do something they expect.

I may try building -cv-bridge with opencv4 using the breadcrumbs at that upstream thread, ditch opencv3-opt completely, and see if that helps.

@jhbruhn
Copy link

jhbruhn commented May 21, 2020

I did also run into troubles trying to compile packages which depend on both cv_bridge and image_geometry, resulting in a linking error with opencv functions. I fixed it by building image_geometry with opencv3 (specified in CMakeLists.txt). It did automatically pick up my OpenCV-4 installation which I had to prevent, although OpenCV3 ist listed as an explicit dependency!

@acxz
Copy link
Member

acxz commented May 21, 2020

Thanks for pointing that out @jhbruhn I believe this issue should be resolved with the noetic release since ROS will not target opencv3 anymore

@jhbruhn
Copy link

jhbruhn commented May 21, 2020

I agree, but shouldn't we be consistent with the OpenCV3 dependencies for melodic still? Or at least decide whether we

  • depend on opencv3-opt and actually use it to build this package
  • or depend on opencv and let CMake choose OpenCV4?

@acxz
Copy link
Member

acxz commented May 21, 2020

yeah we should be consistent esp considering that we get errors when compiling packages depending on it.

Feel free to create a PR regarding this!
I think the first option sounds more appealing.

@acxz
Copy link
Member

acxz commented May 22, 2020

With the merge I'll close this issue.

@acxz acxz closed this as completed May 22, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants