Why do I get runtime errors about FEVAL when running my compiled program?

5 views (last 30 days)
When I compile myMain.m as standalone executable file, there is no warning or error message, but there is an error when I execute myMain.exe in the DOS mode window. The error message is
 
"ERROR: Reference to unknow function objFun from FEVAL in standalone mode".
I don't call FEVAL directly, but I do use function functions.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 23 Apr 2015
The FEVAL command is supported by the MATLAB Compiler and may be called implicitly within a command such as the following:
deg= leastsq('objFun',deg,[],[],A,Dx1period);
LEASTSQ is a "function function." These functions--which include the ODE solvers, minimization routines, and numerical integration routines--take a function name as an argument. The MATLAB Compiler does not know objFun.m is a function that is being passed to LEASTSQ, so it does not compile this function along with the rest of the files that it sees being explicitly called in your program. Consequently the executable code for objFun cannot be found at runtime.
You can work around this problem in one of two ways, both involve telling the Compiler to compile the additional file. The first way to do this is to include the file on the compilation line:
mcc -m myMain.m -a objFun.m
The other method is to use the "%#function" pragma in one of the files of your application. It is a good idea to do this in the files which use the objective function in question, so your code would become
 
function deg=myfile(Key,Dx,degInit)
% Function to do something or other. Called by myMain.
%#function objFun
% Do something
% Call LEASTSQ
deg= leastsq('objFun',deg,[],[],A,Dx1period);
To compile the application now, you need only type
 
mcc -m myMain.m
For a more complete description of what happens with FEVAL in compiled code, see page 5-65 of the MATLAB Compiler User's Guide.

More Answers (0)

Categories

Find more on Function Creation in Help Center and File Exchange

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!