Why does ADDPATH cause an application that is generated with MATLAB Compiler 4.0 (R14) to fail?

24 views (last 30 days)
I have called ADDPATH to add a directory to the MATLAB path either in my startup.m file or in my application. I am able to compile the application, but it errors out when I try to run it.
ERROR: An unknown error occurred while executing MATLAB code.
MCL:Runtime:InternalFeval

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 17 Feb 2021
Edited: MathWorks Support Team on 17 Feb 2021
This behavior is expected to occur on a development machine (a machine with a MATLAB installation) when the directories added by ADDPATH commands contain MATLAB files with the same name as any of the MATLAB files in the compiled application. The reason for this behavior is that ADDPATH adds directories to the front of the MATLAB path. Subsequently, when the MCR (at runtime) looks for a file foo.m, it finds the unencrypted foo.m in one of the directories added by ADDPATH, instead of the compiled and encrypted foo.m that was placed in the CTF archive. Since the MCR cannot execute unencrypted MATLAB files, it issues an error message and the application fails.
ADDPATH will result in an error and program termination on a target machine as well if the path being added does not exist on the machine.
There are two ways to add directories to the path in a safe way:
1. First way is to modify MATLAB's pathdef.m file (MATLAB saves the search path to pathdef.m file), which MATLAB uses but compiled applications ignore.
You can modify pathdef.m from MATLAB command window using functions like ADDPATH and RMPATH. For more information on these functions, please visit the following webpages:
As an alternative, you can use the Set Path GUI utility to edit MATLAB path. To invoke this utility, please execute the following at the MATLAB command window:
pathtool
2. The other way is to protect calls to ADDPATH so that they do not get executed by compiled applications. For example, use a construct like:
if (~isdeployed)
addpath(path);
end

More Answers (0)

Categories

Find more on Search Path 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!