使用图像处理工具箱编译Matlab共享库

发布于 2024-09-25 02:15:21 字数 713 浏览 6 评论 0原文

我正在尝试从 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

月牙弯弯 2024-10-02 02:15:21

您是否尝试过使用 -a 选项包含图像处理工具箱文件夹?例如:

mcc ... -a C:\Program Files\MATLAB\R2009a\toolbox\images\images

根据mcc文档 ,该文件夹中的所有文件以及任何子文件夹中的所有文件都将添加到 CTF 存档中,并且文件夹子树将保留在 CTF 存档中。

如果您不想包含每个子文件夹,则可以使用通配符模式仅加载文件夹中的文件:

mcc ... -a C:\Program Files\MATLAB\R2009a\toolbox\images\images\*

如果子文件夹中的函数或脚本可能会隐藏父文件夹中的函数或脚本,则可能需要这样做。例如,父文件夹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。您不希望在编译时添加此子文件夹,因此您可以:

  1. 暂时删除该子文件夹,添加不带通配符选项的父文件夹(以添加您想要的其他子文件夹),然后放回该文件夹.

  2. 使用通配符选项添加父文件夹(仅添加文件),然后仅添加所需的子文件夹(例如 @strelprivate)一个额外的 -a 命令。 注意:我不确定单独添加子文件夹是否会以与选项 #1 相同的方式维护 CTF 存档中父目录的文件夹子树!

如果您不想包含较大的子文件夹,可能最终不会被使用的文件列表,您可以尝试使用函数 DEPFUN 首先获取 MATLAB 代码的依赖项列表。然后,从此列表中您可以找到您的代码使用的特定图像处理工具箱函数,并且仅包含编译时的函数。由于您特别询问,此新闻组线程提到了如何包含 .mex 文件:

mcc ... -a imreconstructmex.mexw32  %# For a 32-bit Windows mex file

注意:我还遇到了一个 MathWorks 错误报告 (您需要登录才能看到)其中提到在 R2009b 中的 Windows 上使用某些图像处理工具箱功能编译应用程序时出现问题。上面的链接给出了一个解决方法。此错误自 R2010a 起已修复。

Have you tried including the Image Processing Toolbox folder using the -a option? For example:

mcc ... -a C:\Program Files\MATLAB\R2009a\toolbox\images\images

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:

mcc ... -a C:\Program Files\MATLAB\R2009a\toolbox\images\images\*

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 folder C:\Program Files\MATLAB\R2009a\toolbox\images\images\, and there is a ja subfolder that contains Japanese language help files (on Windows), one of which is also called edge.m. You wouldn't want this subfolder to be added when compiling, so you could either:

  1. 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.

  2. Add the parent folder with the wildcard option (to add just the files), then separately add only the subfolders you want (such as @strel and private) 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:

mcc ... -a imreconstructmex.mexw32  %# For a 32-bit Windows 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文