0

I have installed the OpenCV package in Ubuntu22.04 by sudo apt-get.

And the said OpenCV is one of the dependencies for my project.

The problem is that the target computer does not have installed OpenCV and it's impossible to use sudo permission.

How to make the OpenCV that I am using portable by the install command of Cmake? I intend to copy the OpenCV libraries when make install is invoked.

What I have tried is seen below.

Here is a portion of the CMakeLists.txt:

find_package( OpenCV REQUIRED )

message("OpenCV_LIBS:")
foreach(lib  ${OpenCV_LIBS})
message("${lib}")
endforeach()

install(FILES ${OpenCV_LIBS} TYPE LIB)

Here is the output when cmake .. is invoked:

OpenCV_LIBS:
opencv_calib3d
opencv_core
opencv_dnn
opencv_features2d
opencv_flann
opencv_highgui
//omits some similar output

Here is the error message when make install is called:

CMake Error at cmake_install.cmake:130 (file):
  file INSTALL cannot find "/home/john/myproject/opencv_calib3d":
  No such file or directory.

And what's more, how to only make the libraries that the binary program really needs available to the customer other than sending all the libraries of OpenCV to the customer?

Tips: the customer uses the same OS.

John
  • 2,963
  • 11
  • 33
  • Easy option would be to link with OpenCV statically. | The problem with install is likely that you're giving it just library names, but the actual files are located in some system directory. | Personally, instead of linking with every single OpenCV module and letting the linker sort it out, I prefer to explicitly link only with those modules that I actually need. So drop the `${OpenCV_LIBS}`, and start with `opencv_core` and systematically add libraries based on the functions you've used (or based on complaints of the linker). – Dan Mašek Dec 06 '22 at 12:59
  • @DanMašek :) Thank you for the reply. It's a solution. But not an automatic one. ***And*** how to tell the `cmake` to statically link the OpenCV? – John Dec 07 '22 at 09:32
  • Have you checked [that answer](https://stackoverflow.com/questions/52098134/cmake-install-for-targets-and-its-so-dependencies) on the similar question? It suggests to use `install(IMPORTED_RUNTIME_ARTIFACTS)`. – Tsyvarev Dec 14 '22 at 10:42
  • @Tsyvarev For `grpc`, it's `install(IMPORTED_RUNTIME_ARTIFACTS gRPC::grpc)`. What about `OpenCV`? – John Dec 14 '22 at 11:51
  • Actually, `opencv_calib3d`, `opencv_core`, and all other elements in `${OpenCV_LIBS}` are IMPORTED **targets** (And that explains why you have failed to install them via `install(FILES)`). Note, that `install(IMPORTED_RUNTIME_ARTIFACTS)` installs only files directly representing by the those targets. If you want to install indirect dependencies too, then you could look into [file(GET_RUNTIME_DEPENDENCIES)](https://cmake.org/cmake/help/latest/command/file.html#get-runtime-dependencies) command. – Tsyvarev Dec 14 '22 at 12:34

0 Answers0