0

I have a simple program that displays an image using OpenCV 4.3. If I run it in terminal e.g. ./test_opencv it displays the image, however if I double-click the same executable in a Finder window, the read image is empty.

What is the cause of this?

I am including cmake 3.16, apple clang 11.0.3, and am including all opencv libraries.

kib
  • 61
  • 1
  • 4
  • Probably an assumption about the current working directory. If so try using an absolute path to your test image. – Richard Critten May 27 '20 at 12:11
  • Both work with an absolute path. Looking in further `std::filesystem::current_path()` is the absolute path from where I call the executable in terminal and ~ if I run it through Finder. Any idea what the source of this is? – kib May 27 '20 at 12:31

1 Answers1

0

The reason of it is working on terminal is that the program can reach the libraries which it needs. You should add the necessity libraries to environment by adding to .bashrc file.

Open terminal and find the all libraries which the program using by the command:

Ubuntu : ldd <path>

Mac: otool -L <path>

Then open bashrc and add the libraries which are not exist in there. Here is the link for bashrc on mac. Also you should search what is static library and dynamic library means.

Yunus Temurlenk
  • 4,085
  • 4
  • 18
  • 39
  • It is reaching the library. I am only adding opencv and get no errors calling cv::imread and calling member functions of the returned cv::Mat. If I try to display the empty image when launching through Finder, I get an opencv assert exception for the rows and cols being 0. – kib May 27 '20 at 13:33