1

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
  • 2
    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? Commented Oct 18, 2012 at 17:04

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

4 Comments

I realized that otherfunction.m calls another function (let call secondfunction.m), this second function is on the same folder of otherfunction.m, using a try/catch I get: 'Undefined function or method 'secondfunction'. I compile using only the path to the directory as you suggested.
@Lazza87 That's odd. Can you use the GUI to compile, or do you have to use code? You open the GUI compiler by typing 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. Then click the build button. Hopefully that works, because then I'm out of ideas :-)
Using the GUI Compiler it works!! This mean that there is something wrong in the command I used! Anyway thank you!
@Lazza87 I usually use the GUI myself rather than messing with mcc. I'll update my answer to include the GUI solution. If you think the updated answer solves the problem, then feel free to click the tick mark next to it to mark the question answered. ps, glad it works :-)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.