1
votes

I'm trying to compile myfunction.m in matlab. This functions calls another function (otherfunction.m) that is defined in another folder. This fold is added to matlab path so if I run:

myfunction

from Matlab Command Window everything works.

If I try to compile as:

mcc -m myfunction.m -I /CompletePathToOtherFunction otherfunction.m

The exe file doesn't work. How can I manage this?

1
Have you tried 'mcc -m myfunction.m -I /CompletePathToOtherFunction'? And also looked at the output of this with the '-v' option? Any Errors, any warnings? - Tobold

1 Answers

2
votes

From the documentation:

"Passing -I on the Command Line:

You can use the -I option to add a folder to the beginning of the list of paths to use for the current compilation. This feature is useful when you are compiling files that are in folders currently not on the MATLAB path."

So after -I I think you should pass the path to the directory containing otherfunction.m, NOT the path of otherfunction.m itself.

A few other things to check:

  • Use which otherfunction to ensure you're using the right version of otherfunction (if multiple versions exist). If two functions on the path have the same name, Matlab silently defaults to whichever is higher on the path.

  • If the code you are compiling calls a function using eval, then you will need to supply the directory containing that function (or supply the function explicitly), even if that directory is on the matlab path.

  • If all else fails, try using the GUI for the compiler instead of the mcc command. To bring up the GUI, simply type deploytool in the command window. Once you've chosen a project location in the GUI and specified a "console application" (or whatever else you want), then you click on the link "add main file" and add myfunction.m. Then look for the link "add other references/folders" (or something similar), click it, and then manually add the directory(s) containing otherfuncion.m and secondfunction.m.