gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 23:01:18 25 4
gpt4 key购买 nike

我有一个 mex 函数,它使用了我正在尝试使用的 OpenCV。编译似乎工作正常,但是当我尝试在 MATLAB 中调用该函数时,出现此错误:

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 安装位于 /nwdata/username/ (我使用他们文档中的 OpenCV 推荐设置从头开始编译自己)。我使用这个函数用 mex 编译:

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。这是相关的行:

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

好的,所以这看起来没问题。该文件肯定存在:

[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 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。

这看起来很奇怪。有任何想法吗?这台机器是集群的一部分,所以我没有根访问权限或任何东西。

最佳答案

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

关于c++ - MATLAB + Mex + OpenCV : Links and compiles correctly but can't find library at run time,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17647403/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com