Question

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?

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top