使用图像处理工具箱编译Matlab共享库
我正在尝试从 Matlab 编译 C 共享库。我的 Matlab 代码使用了很多图像处理功能。因此,编译进展顺利,但是当我从应用程序调用 dll 时,我收到如下消息:
“对于双精度类型的输入参数,未定义函数或方法‘XYZ’”。
我已经验证了我的论点是正确的——这不是类型问题。因此,我尝试将 %#function XYZ
添加到我的 .m 文件中,但这没有任何帮助。然后,我尝试在编译命令中使用 -a
标志:
eval(['mcc -v -N -W lib:cshared -d ' clibdir ' -T link:lib -a edge' allFiles]);
但它无法编译:
Depfun 错误:“无法将边缘定位为 MATLAB 路径上的函数”
我已验证图像处理文件位于我的计算机上(我可以毫无问题地运行 matlab 中的所有内容),并且我的路径指向包含它们的目录。
我还尝试将工具箱 .m 文件复制到我的工作目录中,但这很快就会增加到很多文件中。而且,对于某些函数,没有 .m - 只有 .mex - 而且我还没有找到将 mex 文件包含到我的 .dll 中的方法。
我缺少什么?
I'm trying to compile C shared library from Matlab. My Matlab code uses a lot of the image processing functionality. So, compiling goes fine, but when I call the dll from my application, I get messages like:
"Undefined function or method 'XYZ' for input arguments of type double".
I have verified my arguments are ok -- it's not a type problem. So, I tried adding %#function XYZ
to my .m file, but that didn't help anything. Then, I tried using the -a
flag in my compile command:
eval(['mcc -v -N -W lib:cshared -d ' clibdir ' -T link:lib -a edge' allFiles]);
but it fails to compile with:
Depfun error: 'Unable to locate edge as a function on the MATLAB path'
I have verified the image processing files are on my computer (I can run everything from matlab with no problem) and my path points to the directory that contains them.
I've also tried copying the toolbox .m files into my working directory, but that quickly balloons into a lot of files. And, for some functions, there is no .m - just a .mex - and i haven't found a way to include a mex file into my .dll.
What am I missing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否尝试过使用
-a
选项包含图像处理工具箱文件夹?例如:根据
mcc
文档 ,该文件夹中的所有文件以及任何子文件夹中的所有文件都将添加到 CTF 存档中,并且文件夹子树将保留在 CTF 存档中。如果您不想包含每个子文件夹,则可以使用通配符模式仅加载文件夹中的文件:
如果子文件夹中的函数或脚本可能会隐藏父文件夹中的函数或脚本,则可能需要这样做。例如,父文件夹
C:\Program Files\MATLAB\R2009a\toolbox\images\images\
中有一个edge.m
函数,并且有一个< a href="http://www.mathworks.com/matlabcentral/newsreader/view_thread/265034" rel="nofollow">ja
包含日语帮助文件的子文件夹(在 Windows 上) ),其中之一也称为edge.m。您不希望在编译时添加此子文件夹,因此您可以:暂时删除该子文件夹,添加不带通配符选项的父文件夹(以添加您想要的其他子文件夹),然后放回该文件夹.
使用通配符选项添加父文件夹(仅添加文件),然后仅添加所需的子文件夹(例如
@strel
和private
)一个额外的-a
命令。 注意:我不确定单独添加子文件夹是否会以与选项 #1 相同的方式维护 CTF 存档中父目录的文件夹子树!如果您不想包含较大的子文件夹,可能最终不会被使用的文件列表,您可以尝试使用函数 DEPFUN 首先获取 MATLAB 代码的依赖项列表。然后,从此列表中您可以找到您的代码使用的特定图像处理工具箱函数,并且仅包含编译时的函数。由于您特别询问,此新闻组线程提到了如何包含 .mex 文件:
注意:我还遇到了一个 MathWorks 错误报告 (您需要登录才能看到)其中提到在 R2009b 中的 Windows 上使用某些图像处理工具箱功能编译应用程序时出现问题。上面的链接给出了一个解决方法。此错误自 R2010a 起已修复。
Have you tried including the Image Processing Toolbox folder using the
-a
option? For example:According to the
mcc
documentation, all files in this folder, as well as all files in any subfolders, are added to the CTF archive, and the folder subtree is preserved in the CTF archive.If you don't want to include every subfolder, you can load only the files in a folder using a wildcard pattern:
This may be necessary if there is a subfolder that may have functions or scripts that could shadow ones in the parent folder. For example, there is an
edge.m
function in the parent folderC:\Program Files\MATLAB\R2009a\toolbox\images\images\
, and there is aja
subfolder that contains Japanese language help files (on Windows), one of which is also callededge.m
. You wouldn't want this subfolder to be added when compiling, so you could either:Remove that subfolder temporarily, add the parent folder without the wildcard option (to add the other subfolders you do want), then put that folder back.
Add the parent folder with the wildcard option (to add just the files), then separately add only the subfolders you want (such as
@strel
andprivate
) with an additional-a
command. NOTE: I'm uncertain if adding subfolders separately will maintain the folder subtree of the parent directory in the CTF archive in the same way as option #1 would!If you don't want to include a large list of files that may not end up being used, you could instead try using the function DEPFUN to first get a list of dependencies for your MATLAB code. Then from this list you can find the specific Image Processing Toolbox functions your code uses and include only those when compiling. Since you specifically asked, this newsgroup thread mentions how to include a .mex file:
NOTE: There is also a MathWorks bug report I came across (which you need a login to see) that mentions a problem compiling applications using some Image Processing Toolbox functions on Windows in R2009b. There is a workaround given at the above link. This bug is fixed as of R2010a.