c++ - MATLAB + Mex + OpenCV: Links and compiles correctly but can't find library at run time -


i have mex function uses opencv i'm trying use. compilation seems work, when try , call function within matlab error:

invalid mex-file '/path/to/project/mexfunction.mexa64': libopencv_legacy.so.2.4: cannot open shared object file: no such file or directory 

my opencv 2.4.5 install located @ /nwdata/username/ (i compiled myself scratch using opencv recommended settings documentation). compile mex using function:

function cvmex(mexfile)     ocv_inc_dir='/nwdata/username/include/opencv';·     ocv2_inc_dir='/nwdata/username/include';·     ocv_lib_dir ='/nwdata/username/lib';·      mex(mexfile,'-g','-v',['-i',ocv2_inc_dir],['-i',ocv_inc_dir],['-l',ocv_lib_dir],'duse_double',...     '-lopencv_legacy','-lopencv_imgproc','-lopencv_core','-lopencv_contrib','-lopencv_ml',...     '-lopencv_objdetect','-lopencv_calib3d','-lopencv_flann','-lopencv_features2d',...     '-lopencv_video','-lopencv_gpu'); end 

when compile, no errors. checked see dependencies of library using ldd mexfunction.mexa64. here relevant line:

libopencv_legacy.so.2.4 => /nwdata/username/lib/libopencv_legacy.so.2.4 (0x00002ad6a2123000)

ok, seems alright. file exists:

[username@machine:/nwdata/username/lib] $ ls -l libopencv_legacy* lrwxrwxrwx 1 username redacted      25 jul 15 15:07 libopencv_legacy.so -> libopencv_legacy.so.2.4.5 lrwxrwxrwx 1 username redacted      25 jul 15 15:07 libopencv_legacy.so.2.4 -> libopencv_legacy.so.2.4.5 -rwxr-xr-x 1 username redacted 1303944 jun 17 15:37 libopencv_legacy.so.2.4.5   [username@machine:/nwdata/username/lib] $ file libopencv_legacy.so* libopencv_legacy.so:       symbolic link `libopencv_legacy.so.2.4.5' libopencv_legacy.so.2.4:   symbolic link `libopencv_legacy.so.2.4.5' libopencv_legacy.so.2.4.5: elf 64-bit lsb shared object, x86-64, version 1 (sysv), dynamically linked, not stripped 

running on linux:

linux machine@redacted 2.6.43.8-1.fc15.x86_64 #1 smp mon jun 4 20:33:44 utc 2012 x86_64 x86_64 x86_64 gnu/linux

matlab r2011b, , g++ 4.6.3.

this seems odd. ideas? machine part of cluster, don't have root access or anything.

i encountered similar problem days ago. problem happens when using matlab remotely on cluster. editing ld_library_file in matlab useless, , don't know why. solved problem defining ld_library_path in .bashrc (or .bash_profile).


Comments