Invalid MEX-file libopencv_core.so.2.4: cannot open shared object file: No such file or directory

Hi,
Sorry my question may be a little bit long because I need to explain the steps to get this error.
So I was trying to run this somewhat old (2014) matlab code here to calibrate the omnicam on a linux computer. You can get the download link from their site "Calibration code for Linux/Windows (including test images): libomnical.zip (50 MB)"
And following its readme, to install, you should first set up paths in init.m and run make.m under the /src folder. There I met several errors, some are the same in this solution, and the other complains not finding <opencv2/opencv.hpp>, so eventually I change the line in the make.m under /src/Mapping/Geometry_Model/Projection/Mex, from
mex('rodriguesMex.cpp',['-L',opts.opencv_lib_dir], '-lopencv_core', '-lopencv_imgproc', '-lopencv_highgui', '-lopencv_features2d', '-lopencv_calib3d')
to
mex('rodriguesMex.cpp',['-L',opts.opencv_lib_dir], ['-I"',opts.opencv_inc_dir,'"'],'-lopencv_core', '-lopencv_imgproc', '-lopencv_highgui', '-lopencv_features2d', '-lopencv_calib3d')
to add include directory.
Now I can successfully run the make.m under /src to install. And I'm going to run the calibration code, which is "omni_calibration.m" under /src/Calibration. However it returns with this error message:
Invalid MEX-file
'/media/kudo/toshiba_4T/omnicam/libomnical/LibOmniCal/src/Mapping/Geometry_Model/Projection/Mex/rodriguesMex.mexa64':
libopencv_core.so.2.4: cannot open shared object file: No such file or directory
and I have no clue why it would happen since I thought properly installed it and this file "libopencv_core.so.2.4" is actually in my lib directory.
opts.opencv_lib_dir = '/home/kudo/anaconda3/pkgs/opencv-2.4.11-nppy27_0/lib';
opts.opencv_inc_dir = '/home/kudo/anaconda3/pkgs/opencv-2.4.11-nppy27_0/include';
and
(base) kudo@alien:~/anaconda3/pkgs/opencv-2.4.11-nppy27_0/lib/opencv2$ locate libopencv_core.so.2.4
/home/kudo/anaconda3/pkgs/opencv-2.4.11-nppy27_0/lib/libopencv_core.so.2.4
/home/kudo/anaconda3/pkgs/opencv-2.4.11-nppy27_0/lib/libopencv_core.so.2.4.11
Please help since this is a reletaively old code and may not be maintained anymore.
Thanks in advance!

1 commentaire

Could you verify that your two libopencv_core_so.2.4* files are real files? Or at least that if the .2.4 file is a link that it points to someplace that exists or is a hard-link to the .11 file ?

Connectez-vous pour commenter.

 Réponse acceptée

Two things to try.
  1. On linux, ldd is a very useful tool. Try ldd rodriguesMex.mexa64. This will tell you if all the symbols can be resolved
  2. Your opts.opencv_lib_dir = '/home/kudo/anaconda3/pkgs/opencv-2.4.11-nppy27_0/lib'; is only used for linking the mex64, but might not be used for running it. You might need to set the LD_LIBRARY_PATH env var to point to this lib dir as well.
Thanks,
Yongjian

3 commentaires

Yongjian,
Thanks for the quick reply. I followed your first suggestion using ldd to check the links:
(base) kudo@alien:/media/kudo/toshiba_4T/omnicam/libomnical/LibOmniCal/src/Mapping/Geometry_Model/Projection/Mex$ ldd rodriguesMex.mexa64
linux-vdso.so.1 (0x00007ffef7da8000)
libopencv_core.so.2.4 => not found
libopencv_calib3d.so.2.4 => not found
libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007fc424424000)
libmx.so => not found
libmex.so => not found
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007fc424407000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fc424215000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fc4240c6000)
/lib64/ld-linux-x86-64.so.2 (0x00007fc424657000)
Obviously some shared liibraries are not found. So I followed your second suggestion set the LD_LIBRARY_PATH. After I followed solution (apprantly it is the same as setting that in a bash shell, no difference to matlab) to set up the LD_LIBRARY_PATH for MATLAB by
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/kudo/anaconda3/pkgs/opencv-2.4.11-nppy27_0/lib
and rerun the MATLAB, it now runs without a problem.
So big thanks!
P.S. just aside, I noticed that other than the two opencv libraries, there are two other libraries libmx.so and libmex.so also not found. But it seems they do not affect the execution. To be fair, I later added /usr/local/MATLAB/R2021a/bin/glnxa64 also to the LD_LIBRARY_PATH to make the "not found" disappear, but I just wonder why it should work in the first place.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Programming dans Centre d'aide et File Exchange

Produits

Version

R2021a

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by