MATLAB + Mex + OpenCV:链接和编译正确,但在运行时找不到库 [英] MATLAB + Mex + OpenCV: Links and compiles correctly but can't find library at run time

查看:3655
本文介绍了MATLAB + Mex + OpenCV:链接和编译正确,但在运行时找不到库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 mex 函数,它使用 OpenCV ,我想使用。编译似乎工作,但当我尝试调用 MATLAB 中的函数时,我得到这个错误:

I have a mex function which uses OpenCV that I'm trying to use. The compilation seems to work, but when I try and call the function within MATLAB I get this error:

Invalid MEX-file '/path/to/project/mexfunction.mexa64': libopencv_legacy.so.2.4: cannot open shared object file: No such file or directory

我的 OpenCV 2.4.5 install位于 nwdata / username / (我使用OpenCV推荐的设置从头开始编译自己的文档)。我使用这个函数编译mex:

My OpenCV 2.4.5 install is located at /nwdata/username/ (I compiled myself from scratch using the OpenCV recommended settings from their documentation). I compile with mex using this 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

当我编译时,我没有错误。然后我检查看看库的依赖关系使用 ldd mexfunction.mexa64 。以下是相关行:

When I compile, I get no errors. I then checked to see what the dependencies of the library are using ldd mexfunction.mexa64. Here is the relevant line:

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

好吧,好像没事了。该文件肯定存在:

Ok, so that seems alright. That file definitely 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 to `libopencv_legacy.so.2.4.5'
libopencv_legacy.so.2.4:   symbolic link to `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

在Linux上运行:

Linux机器@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。

有任何想法吗?这个机器是集群的一部分,所以我没有root权限或任何东西。

This seems odd. Any ideas? This machine is part of a cluster, so I don't have root access or anything.

推荐答案

几天前。只有在集群上远程使用matlab时,才会出现此问题。在Matlab中编辑LD_LIBRARY_FILE是无用的,我不知道为什么。我通过在.bashrc(或.bash_profile)中定义LD_LIBRARY_PATH来解决这个问题。

I encountered a similar problem some days ago. This problem only happens when you using the matlab remotely on a cluster. Editing the LD_LIBRARY_FILE in Matlab is useless, and I don't know why. I solved the problem by defining the LD_LIBRARY_PATH in .bashrc (or .bash_profile).

这篇关于MATLAB + Mex + OpenCV:链接和编译正确,但在运行时找不到库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆