views:

44

answers:

1

Hi all,

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?

A: 

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.

gnovice
thanks for the response...i think i'm closer now. however, now i'm getting a runtime error, "attempt to execute script as a function: c:\...\edge.m". i'm guessing because edge is shadowed (it has a .m and a .mex). i there some way to tell mcc to correctly resolve shadowed functions? i'm guessing edge isn't the only one that will hhave this issue.
mike
btw, i'm using 2008B.
mike
@mike: In my version of MATLAB (R2009a), I can see a function "edge.m" in the folder "C:\Program Files\MATLAB\R2009a\toolbox\images\images". There are three folders there as well: "@strel", "ja", and "private". I didn't find a .mex file for "edge". The only folder that I find another file named "edge" in is the "ja" folder, which has another "edge.m" that appears to be nothing but comments. I will update my answer shortly with a potential way around this.
gnovice
thanks so much gnovice. i'm still working on using your advice, but it's looking promising. i feel like this should be an environment issue though, because a ja folder exist in other places too (for example, toolbox/images/iptutils -- which i need). so i can see my compile command becoming quite out of hand with so many -a full-path arguments. not to mention, if someone else on the team goes to run my build script, i would rather they not have to deal with differing paths, etc. also seems weird that i haven't found this problem on google at all.
mike