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

fix compatibility with OpenCV 4.x #13

Merged
merged 3 commits into from
Aug 25, 2020
Merged

fix compatibility with OpenCV 4.x #13

merged 3 commits into from
Aug 25, 2020

Conversation

doudou
Copy link
Member

@doudou doudou commented May 11, 2020

CMakeLists.txt Outdated Show resolved Hide resolved
@annaborn
Copy link

annaborn commented May 11, 2020

I just tested it inside my project buildconf. I have issues
1.

CMake Error at CMakeLists.txt:9 (rock_init):
  rock_init Macro invoked with incorrect arguments for macro named: rock_init

I fixed it with rock_init(frame_helper 0.1)

  1. The frame_helper was linked agains opencv 4.2 even if OPENCV4 was set OFF. I would expect that in this case it will take the older os opencv version. Is it correct?
  2. If the OPENCV4 is set to ON. No Opencv4 can be found
-- Checking for module 'opencv4'
--   No package 'opencv4' found
CMake Error at /usr/share/cmake-3.10/Modules/FindPkgConfig.cmake:415 (message):
  A required package was not found

Probably, it is matter of the project setup.

@doudou
Copy link
Member Author

doudou commented May 11, 2020

About the CMake stuff, that's the meaning of

Depends on:
- [ ] rock-core/base-cmake#58

The frame_helper was linked agains opencv 4.2 even if OPENCV4 was set OFF. I would expect that in this case it will take the older os opencv version. Is it correct?

It should, at least that was my assumption. I was letting our CI test it. Can you do pkg-config --cflags opencv and pkg-config --cflags opencv4 with Rock's env.sh loaded ?

I haven't added explicit version checks. I definitely should.

@doudou doudou requested a review from 2maz May 11, 2020 21:27
@annaborn
Copy link

annaborn commented May 11, 2020

About the CMake stuff, that's the meaning of

Depends on:
- [ ] rock-core/base-cmake#58

Sorry, just took a look inside the dep after my first post.

I fixed the issue with not found opencv4.
By opencv4 Pkgconfig file is not generated automaticly. Opencv has dropped the support for pkgconfig (s. opencv/opencv#13154) I have to set OPENCV_GENERATE_PKGCONFIG=ON to generate the pkgconfig

But the 2. issue remains.

Here is output fo pkg-config with env.sh loaded:

...perception/frame_helper$ pkg-config --cflags opencv
-I/usr/include/opencv
...perception/frame_helper$ pkg-config --cflags opencv4
pkg-config --cflags opencv4
-I/.../rock/install/include/opencv4/opencv -I/.../rock/install/include/opencv4


opencv is 3.2 and installed by rock as os dep under system location
opencv4 is 4.2 and installed by rock as source package under rock/install

@doudou
Copy link
Member Author

doudou commented May 12, 2020

Note that "sometimes" CMake "forgets" to rebuild things. Try maybe to clean the build between changes to OPENCV4 (if you haven't already) ?

So far, the introduction of this patch does not break the build on Ubuntu 18.04, which I would expect if it was trying to resolve opencv4

@doudou
Copy link
Member Author

doudou commented May 14, 2020

@annaborn do you still have problems ? I can vouch that it builds on 18.04 with a "normal" environment and on 20.04 with Ubuntu's packaged opencv 4. Have you figured out your problem with the self-built opencv ?

@doudou doudou marked this pull request as ready for review May 14, 2020 23:57
@annaborn
Copy link

@doudou I did not have time to test it, but I will do it today or next days.
Since I could use this solution for other libs in our buildconf, that depends on opencv.

@annaborn
Copy link

annaborn commented May 20, 2020

@doudou: Even in new buildconf check the problem remains. After external/opencv4.2 gets installed, frame_helper links against it, not against opencv3.2 how it is expected if OPENCV4 has been set to OFF.

From CMakeCache.txt you can see that pkgconfig_lib is set wrong:

//Whether OpenCV 4 or later should be used
OPENCV4:BOOL=OFF
//Path to a library.
_opencv_PKGCONFIG_lib:FILEPATH=/home/linki/DFKI/ROCK/transfit_mmi_2/install/lib/libopencv_core.so

Also LIB_DEPENDS contains a mix of opencv lib from system and from rock install.

//Dependencies for the target
frame_helper_ruby_LIB_DEPENDS:STATIC=general;/usr/lib/x86_64-linux-gnu/libopencv_shape.so;general;/home/linki/DFKI/ROCK/transfit_mmi_2/install/lib/libopencv_stitching.so;general;/usr/lib/x86_64-linux-gnu/libopencv_superres.so;general;/usr/lib/x86_64-linux-gnu/libopencv_videostab.so;general;/usr/lib/x86_64-linux-gnu/libopencv_aruco.so;general;/usr/lib/x86_64-linux-gnu/libopencv_bgsegm.so;general;/usr/lib/x86_64-linux-gnu/libopencv_bioinspired.so;general;/usr/lib/x86_64-linux-gnu/libopencv_ccalib.so;general;/usr/lib/x86_64-linux-gnu/libopencv_datasets.so;general;/usr/lib/x86_64-linux-gnu/libopencv_dpm.so;general;/usr/lib/x86_64-linux-gnu/libopencv_face.so;general;/usr/lib/x86_64-linux-gnu/libopencv_freetype.so;general;/usr/lib/x86_64-linux-gnu/libopencv_fuzzy.so;general;/usr/lib/x86_64-linux-gnu/libopencv_hdf.so;general;/usr/lib/x86_64-linux-gnu/libopencv_line_descriptor.so;general;/usr/lib/x86_64-linux-gnu/libopencv_optflow.so;general;/home/linki/DFKI/ROCK/transfit_mmi_2/install/lib/libopencv_video.so;general;/usr/lib/x86_64-linux-gnu/libopencv_plot.so;general;/usr/lib/x86_64-linux-gnu/libopencv_reg.so;general;/usr/lib/x86_64-linux-gnu/libopencv_saliency.so;general;/usr/lib/x86_64-linux-gnu/libopencv_stereo.so;general;/usr/lib/x86_64-linux-gnu/libopencv_structured_light.so;general;/usr/lib/x86_64-linux-gnu/libopencv_phase_unwrapping.so;general;/usr/lib/x86_64-linux-gnu/libopencv_rgbd.so;general;/usr/lib/x86_64-linux-gnu/libopencv_viz.so;general;/usr/lib/x86_64-linux-gnu/libopencv_surface_matching.so;general;/usr/lib/x86_64-linux-gnu/libopencv_text.so;general;/usr/lib/x86_64-linux-gnu/libopencv_ximgproc.so;general;/home/linki/DFKI/ROCK/transfit_mmi_2/install/lib/libopencv_calib3d.so;general;/home/linki/DFKI/ROCK/transfit_mmi_2/install/lib/libopencv_features2d.so;general;/home/linki/DFKI/ROCK/transfit_mmi_2/install/lib/libopencv_flann.so;general;/usr/lib/x86_64-linux-gnu/libopencv_xobjdetect.so;general;/home/linki/DFKI/ROCK/transfit_mmi_2/install/lib/libopencv_objdetect.so;general;/home/linki/DFKI/ROCK/transfit_mmi_2/install/lib/libopencv_ml.so;general;/usr/lib/x86_64-linux-gnu/libopencv_xphoto.so;general;/home/linki/DFKI/ROCK/transfit_mmi_2/install/lib/libopencv_highgui.so;general;/home/linki/DFKI/ROCK/transfit_mmi_2/install/lib/libopencv_videoio.so;general;/home/linki/DFKI/ROCK/transfit_mmi_2/install/lib/libopencv_imgcodecs.so;general;/home/linki/DFKI/ROCK/transfit_mmi_2/install/lib/libopencv_photo.so;general;/home/linki/DFKI/ROCK/transfit_mmi_2/install/lib/libopencv_imgproc.so;general;/home/linki/DFKI/ROCK/transfit_mmi_2/install/lib/libopencv_core.so;general;/home/linki/DFKI/ROCK/transfit_mmi_2/install/lib/librtt-typelib-gnulinux.so;general;/home/linki/DFKI/ROCK/transfit_mmi_2/install/lib/liborocos-rtt-gnulinux.so;general;/usr/lib/x86_64-linux-gnu/libpthread.so;general;/usr/lib/x86_64-linux-gnu/librt.so;general;/home/linki/DFKI/ROCK/transfit_mmi_2/install/lib/libtypeLib.so;general;/home/linki/DFKI/ROCK/transfit_mmi_2/install/lib/libbase-types.so;general;/home/linki/DFKI/ROCK/transfit_mmi_2/install/lib/libbase-logging.so;general;/usr/lib/x86_64-linux-gnu/libruby-2.5.so;general;/home/linki/.local/share/autoproj/gems/ruby/2.5.0/gems/rice-2.2.0/ruby/lib/lib/librice.a;general;frame_helper;general;/home/linki/.local/share/autoproj/gems/ruby/2.5.0/gems/rice-2.2.0/ruby/lib/lib/librice.a;

I looked inside of Rock.cmake. The problem starts from rock_find_pkgconfig:

291:   find_library(_${VARIABLE}_lib NAMES ${${VARIABLE}_lib} HINTS ${${VARIABLE}_LIBRARY_DIRS})

Theoretically, the find_library should look for opencv only under the path, that is stored under opencv_PKGCONFIG_LIBRARY_DIRS, but it is empty.
Only opencv_PKGCONFIG_LIBDIR:INTERNAL is set.

In case of opencv4.2 both pathes are set correctly.

Output for build frame_helper with opencv 3.2 (OPENCV4 OFF)

opencv_PKGCONFIG_CFLAGS:INTERNAL=-I/usr/include/opencv
opencv_PKGCONFIG_CFLAGS_I:INTERNAL=
opencv_PKGCONFIG_CFLAGS_OTHER:INTERNAL=
opencv_PKGCONFIG_FOUND:INTERNAL=1
opencv_PKGCONFIG_INCLUDEDIR:INTERNAL=
opencv_PKGCONFIG_INCLUDE_DIRS:INTERNAL=/usr/include/opencv
opencv_PKGCONFIG_LDFLAGS:INTERNAL=-lopencv_shape;-lopencv_stitching;-lopencv_superres;-lopencv_videostab;-lopencv_aruco;-lopencv_bgsegm;-lopencv_bioinspired;-lopencv_ccalib;-lopencv_datasets;-lopencv_dpm;-lopencv_face;-lopencv_freetype;-lopencv_fuzzy;-lopencv_hdf;-lopencv_line_descriptor;-lopencv_optflow;-lopencv_video;-lopencv_plot;-lopencv_reg;-lopencv_saliency;-lopencv_stereo;-lopencv_structured_light;-lopencv_phase_unwrapping;-lopencv_rgbd;-lopencv_viz;-lopencv_surface_matching;-lopencv_text;-lopencv_ximgproc;-lopencv_calib3d;-lopencv_features2d;-lopencv_flann;-lopencv_xobjdetect;-lopencv_objdetect;-lopencv_ml;-lopencv_xphoto;-lopencv_highgui;-lopencv_videoio;-lopencv_imgcodecs;-lopencv_photo;-lopencv_imgproc;-lopencv_core
opencv_PKGCONFIG_LDFLAGS_OTHER:INTERNAL=
----->opencv_PKGCONFIG_LIBDIR:INTERNAL=/usr/lib/x86_64-linux-gnu
opencv_PKGCONFIG_LIBRARIES:INTERNAL=/usr/lib/x86_64-linux-gnu/libopencv_shape.so;/home/linki/DFKI/ROCK/transfit_mmi_2/install/lib/libopencv_stitching.so;/usr/lib/x86_64-linux-gnu/libopencv_superres.so;/usr/lib/x86_64-linux-gnu/libopencv_videostab.so;/usr/lib/x86_64-linux-gnu/libopencv_aruco.so;/usr/lib/x86_64-linux-gnu/libopencv_bgsegm.so;/usr/lib/x86_64-linux-gnu/libopencv_bioinspired.so;/usr/lib/x86_64-linux-gnu/libopencv_ccalib.so;/usr/lib/x86_64-linux-gnu/libopencv_datasets.so;/usr/lib/x86_64-linux-gnu/libopencv_dpm.so;/usr/lib/x86_64-linux-gnu/libopencv_face.so;/usr/lib/x86_64-linux-gnu/libopencv_freetype.so;/usr/lib/x86_64-linux-gnu/libopencv_fuzzy.so;/usr/lib/x86_64-linux-gnu/libopencv_hdf.so;/usr/lib/x86_64-linux-gnu/libopencv_line_descriptor.so;/usr/lib/x86_64-linux-gnu/libopencv_optflow.so;/home/linki/DFKI/ROCK/transfit_mmi_2/install/lib/libopencv_video.so;/usr/lib/x86_64-linux-gnu/libopencv_plot.so;/usr/lib/x86_64-linux-gnu/libopencv_reg.so;/usr/lib/x86_64-linux-gnu/libopencv_saliency.so;/usr/lib/x86_64-linux-gnu/libopencv_stereo.so;/usr/lib/x86_64-linux-gnu/libopencv_structured_light.so;/usr/lib/x86_64-linux-gnu/libopencv_phase_unwrapping.so;/usr/lib/x86_64-linux-gnu/libopencv_rgbd.so;/usr/lib/x86_64-linux-gnu/libopencv_viz.so;/usr/lib/x86_64-linux-gnu/libopencv_surface_matching.so;/usr/lib/x86_64-linux-gnu/libopencv_text.so;/usr/lib/x86_64-linux-gnu/libopencv_ximgproc.so;/home/linki/DFKI/ROCK/transfit_mmi_2/install/lib/libopencv_calib3d.so;/home/linki/DFKI/ROCK/transfit_mmi_2/install/lib/libopencv_features2d.so;/home/linki/DFKI/ROCK/transfit_mmi_2/install/lib/libopencv_flann.so;/usr/lib/x86_64-linux-gnu/libopencv_xobjdetect.so;/home/linki/DFKI/ROCK/transfit_mmi_2/install/lib/libopencv_objdetect.so;/home/linki/DFKI/ROCK/transfit_mmi_2/install/lib/libopencv_ml.so;/usr/lib/x86_64-linux-gnu/libopencv_xphoto.so;/home/linki/DFKI/ROCK/transfit_mmi_2/install/lib/libopencv_highgui.so;/home/linki/DFKI/ROCK/transfit_mmi_2/install/lib/libopencv_videoio.so;/home/linki/DFKI/ROCK/transfit_mmi_2/install/lib/libopencv_imgcodecs.so;/home/linki/DFKI/ROCK/transfit_mmi_2/install/lib/libopencv_photo.so;/home/linki/DFKI/ROCK/transfit_mmi_2/install/lib/libopencv_imgproc.so;/home/linki/DFKI/ROCK/transfit_mmi_2/install/lib/libopencv_core.so
----->opencv_PKGCONFIG_LIBRARY_DIRS:INTERNAL=
opencv_PKGCONFIG_LIBS:INTERNAL=
opencv_PKGCONFIG_LIBS_L:INTERNAL=
opencv_PKGCONFIG_LIBS_OTHER:INTERNAL=
opencv_PKGCONFIG_LIBS_PATHS:INTERNAL=
opencv_PKGCONFIG_PREFIX:INTERNAL=/usr

Output for build frame_helper with opencv 4.2 (OPENCV4 ON)

opencv4_PKGCONFIG_CFLAGS:INTERNAL=-I/home/linki/DFKI/ROCK/transfit_mmi_2/install/include/opencv4/opencv;-I/home/linki/DFKI/ROCK/transfit_mmi_2/install/include/opencv4
opencv4_PKGCONFIG_CFLAGS_I:INTERNAL=
opencv4_PKGCONFIG_CFLAGS_OTHER:INTERNAL=
opencv4_PKGCONFIG_FOUND:INTERNAL=1
opencv4_PKGCONFIG_INCLUDEDIR:INTERNAL=
opencv4_PKGCONFIG_INCLUDE_DIRS:INTERNAL=/home/linki/DFKI/ROCK/transfit_mmi_2/install/include/opencv4/opencv;/home/linki/DFKI/ROCK/transfit_mmi_2/install/include/opencv4
opencv4_PKGCONFIG_LDFLAGS:INTERNAL=-L/home/linki/DFKI/ROCK/transfit_mmi_2/install/lib;-lopencv_dnn;-lopencv_gapi;-lopencv_highgui;-lopencv_ml;-lopencv_objdetect;-lopencv_photo;-lopencv_stitching;-lopencv_video;-lopencv_calib3d;-lopencv_features2d;-lopencv_flann;-lopencv_videoio;-lopencv_imgcodecs;-lopencv_imgproc;-lopencv_core
opencv4_PKGCONFIG_LDFLAGS_OTHER:INTERNAL=
----->opencv4_PKGCONFIG_LIBDIR:INTERNAL=/home/linki/DFKI/ROCK/transfit_mmi_2/install/lib
opencv4_PKGCONFIG_LIBRARIES:INTERNAL=/home/linki/DFKI/ROCK/transfit_mmi_2/install/lib/libopencv_dnn.so;/home/linki/DFKI/ROCK/transfit_mmi_2/install/lib/libopencv_gapi.so;/home/linki/DFKI/ROCK/transfit_mmi_2/install/lib/libopencv_highgui.so;/home/linki/DFKI/ROCK/transfit_mmi_2/install/lib/libopencv_ml.so;/home/linki/DFKI/ROCK/transfit_mmi_2/install/lib/libopencv_objdetect.so;/home/linki/DFKI/ROCK/transfit_mmi_2/install/lib/libopencv_photo.so;/home/linki/DFKI/ROCK/transfit_mmi_2/install/lib/libopencv_stitching.so;/home/linki/DFKI/ROCK/transfit_mmi_2/install/lib/libopencv_video.so;/home/linki/DFKI/ROCK/transfit_mmi_2/install/lib/libopencv_calib3d.so;/home/linki/DFKI/ROCK/transfit_mmi_2/install/lib/libopencv_features2d.so;/home/linki/DFKI/ROCK/transfit_mmi_2/install/lib/libopencv_flann.so;/home/linki/DFKI/ROCK/transfit_mmi_2/install/lib/libopencv_videoio.so;/home/linki/DFKI/ROCK/transfit_mmi_2/install/lib/libopencv_imgcodecs.so;/home/linki/DFKI/ROCK/transfit_mmi_2/install/lib/libopencv_imgproc.so;/home/linki/DFKI/ROCK/transfit_mmi_2/install/lib/libopencv_core.so
----->opencv4_PKGCONFIG_LIBRARY_DIRS:INTERNAL=/home/linki/DFKI/ROCK/transfit_mmi_2/install/lib
opencv4_PKGCONFIG_LIBS:INTERNAL=
opencv4_PKGCONFIG_LIBS_L:INTERNAL=
opencv4_PKGCONFIG_LIBS_OTHER:INTERNAL=
opencv4_PKGCONFIG_LIBS_PATHS:INTERNAL=
´´´

@doudou
Copy link
Member Author

doudou commented May 20, 2020

Theoretically, the find_library should look for opencv only under the path, that is stored under opencv_PKGCONFIG_LIBRARY_DIRS, but it is empty.

That is not exactly true. The dirs are used as a hint, since pkg-config filter out system paths...

And herein lies the problem.

I've been building all my projects for year with autoproj's separate_prefixes set to true. You're obviously not, so another dependency of frame_helper already added ${prefix}/lib to the lib path, and find_library finds it.

You found the right place indeed. The find_library call should only consider paths that are provided within the pkg-config file and no other. This means that when empty, it should be restricted to system paths. Not sure whether it's feasible.

I just created rock-core/base-cmake#60.

However, there's another problem: include path collision. In this particular instance, there's no way to make sure you pick the right opencv: the CMake macros resolve the full path to the libraries, but the compiler is resolving the path to the includes and all of them need to be passed "as one".

The most robust way to solve your particular problem is to enable separate prefixes in autoproj. It will make the dependencies a lot stricter (so, be aware that you might discover non-existing dependencies).

The surest way is to delete the current prefix, .autoproj and autoproj and re-run autoproj_bootstrap from within the same workspace, but this time with --separate-prefixes. Enabling it in the config file and re-running amake might also work, but I'm not sure. If you want to enable for all bootstraps of your project, you can set it in the buildconf init.rb with

Autoproj.config.separate_prefixes = true

If you want to set it for all workspaces on your machine, add the line in ~/.autoprojrc.

Once it is set, you can also set Autobuild::CMake.delete_obsolete_files_in_prefix, which will make autoproj delete files in the install folder that aren't installed anymore (i.e. old stuff), which avoids e.g. depending on headers that have been deleted. I personally have

Autobuild::CMake.delete_obsolete_files_in_prefix = Autoproj.config.separate_prefixes?

in my .autoprojrc

@doudou
Copy link
Member Author

doudou commented Aug 22, 2020

I would appreciate if we could move on with this. This is holding Rock building on Ubuntu 20.04 @annaborn @2maz

Copy link
Member

@2maz 2maz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally the changes look fine to me, but since rock-core/base-cmake/pull/64 is still open some minor changes to CMakeLists.txt might still be required.

@doudou doudou merged commit 5148440 into master Aug 25, 2020
@doudou doudou deleted the opencv4 branch August 25, 2020 00:14
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

Successfully merging this pull request may close these issues.

3 participants