Matlab缺少依赖项MEX文件 [英] Matlab missing dependency MEX-file

查看:708
本文介绍了Matlab缺少依赖项MEX文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在matlab中有一个脚本可以调用其他库.我在Linux上使用matlab版本2012a.我遇到错误,并且不知道如何解决.

I have a script in matlab that calls other libraries. I use matlab version 2012a on linux . I get below error and I don't know how to fix it.

错误是:

无效的MEX文件'/home/XXX/nearest_neighbors.mexa64': libflann.so.1.8:无法打开共享库文件:无此文件或 目录

Invalid MEX-file '/home/XXX/nearest_neighbors.mexa64': libflann.so.1.8: cannot open shared object file: No such file or directory

flann_search中的错误(第82行) [indices,dists] =最近的邻居("find_nn",数据,测试集,n,参数);

Error in flann_search (line 82) [indices,dists] = nearest_neighbors('find_nn', data, testset, n, params);

MyScript中的错误(第73行) [nresult,ndists] = flann_search(Ntraindata',Ntraindata',resu.KNN,struct('algorithm','composite',...

Error in MyScript (line 73) [nresult, ndists] = flann_search(Ntraindata', Ntraindata', resu.KNN, struct('algorithm','composite',...

推荐答案

您所指的那个库- https://github.com/mariusmuja/flann/-具有用MEX代码编写的nearest_neighbors函数. MEX代码是用于与MATLAB接口的C代码.人们通常会在MEX中编写大量的计算负担代码,因为它可以更快地处理循环和其他事物.输入来自MATLAB,并发送到此MEX函数,输出来自MEX函数,并通过管道传递回MATLAB.从根本上讲,它是一个不错的黑匣子,您可以在其中使用它,就像其他任何MATLAB函数一样.实际上,MATLAB随附的许多功能都编写了MEX包装器来促进加速.

That library you are referring to - https://github.com/mariusmuja/flann/ - has the nearest_neighbors function written in MEX code. MEX code is C code that is used to interface with MATLAB. People usually write heavily computationally burdening code over in MEX as it is known to handle loops and other things faster. The inputs come from MATLAB and are sent to this MEX function, and the outputs come from the MEX function and are piped back to MATLAB. It's basically a nice black box where you can use it just like any other MATLAB function. In fact, a lot of the functions that come shipped with MATLAB have MEX wrappers written to promote acceleration.

出现此错误是因为您需要编译 nearest_neighbors函数,以便可以在MATLAB中调用MEX包装器.该包装器丢失了,因为您尚未编译代码.

You are getting that error because you need to compile the nearest_neighbors function so that there is a MEX wrapper that can be called in MATLAB. That wrapper is missing because you haven't compiled the code.

首先,您需要设置MEX.确保您具有与您的MATLAB版本兼容的编译器.您可以通过以下链接来做到这一点:

First, you need to set up MEX. Make sure you have a compiler that is compatible with your version of MATLAB. You can do that by visiting this link:

http://www.mathworks.com/support/compilers/R20xxy/index.html

xx是属于您的MATLAB的版本号,y是其后的字符代码.例如,如果您使用的是R2013a,则可以访问:

xx is the version number that belongs to your MATLAB and y is the character code that comes after it. For example, if you are using R2013a, you would visit:

http://www.mathworks.com/support/compilers/R2013a/index.html

在该位置后,请进入操作系统,并确保已安装其中一种受支持的编译器.安装完成后,进入MATLAB,然后在命令提示符下键入:

Once you're there, go to your Operating System and ensure you have one of those supported compilers installed. Once you have that installed, go into MATLAB, and in the command prompt, type in:

mex -setup

这将允许您设置MEX并选择所需的编译器.鉴于您的错误,您正在使用64位Linux,因此获取GCC应该非常容易.只要确保您选择的GCC版本与您的MATLAB版本兼容即可.选择编译器后,可以在命令提示符下执行以下操作来编译代码:

This will allow you to set up MEX and choose the compiler you want. Given your error, you're using Linux 64-bit, so it should be very easy for you to get GCC. Just make sure that you choose a version of GCC that is compatible with your version of MATLAB. Once you choose the compiler, you can compile the code by doing this in the command prompt:

>> mex -v -O nearest_neighbors.cpp

这将为您生成nearest_neighbors MEX文件.完成后,您现在可以运行代码.

This should generate the nearest_neighbors MEX file for you. Once that's done, you can now run the code.

有关更多详细说明,请查阅FLANN的用户手册-

For more detailed instructions, check out FLANN's user manual - http://people.cs.ubc.ca/~mariusm/uploads/FLANN/flann_manual-1.8.4.pdf - It tells you how to build and compile it for MATLAB use.

祝你好运!

这篇关于Matlab缺少依赖项MEX文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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