Deployed Matlab function with strage errors: functions not found
6 views (last 30 days)
Show older comments
Christian D
on 27 Sep 2024
Commented: Christian D
on 30 Sep 2024
Hi there,
I have a new company PC and had to install MATLAB on this PC. I'm currently facing some strange behaviour when deploying my functions and tools written with MATLAB.
I'm using ether MATLAB 2015aSP1 or 2015b as those two versions were the last providing 32bit support. The programs had to run also on older machine PCs therefore this restriction.
However when deploying even a simple function or small tool I always get some strange errors like the self written functions are not found (those functions are in a folder known to MATLAB). When running the functions or programs by MATLAB it works fine. The deployed version does not run.
I've installed the latest update for both MATLAB versions.
Im Using Windows 10 Enterprise (Version 10.019045). The MATLAB version is 8.5.1.959712 (R2015a) Service Pack 1 Update 3.
The first error is in which I run with startup.m
savepath('pathdef.m');
The error says "Error using savepath. Too many input arguments"
Canceling out this line I get errors on other lines. It seems that the depolyed version does not find the folder with all the user functions.
The make it more complicated: on my old company PC it worked fine.
Kind regards,
Christian
0 Comments
Accepted Answer
Image Analyst
on 29 Sep 2024
Christian:
See the FAQ: https://matlab.fandom.com/wiki/FAQ#My_standalone_executable_won't_run_on_the_target_computer._What_can_I_try?
for some things to consider.
The deployed executable will run the startup.m code that was on the computer that compiled the code into a standalone executable. I'm pretty sure you should not use cd() or savepath() in your deployed code. There are a few reasons why but one of them is that the target computer may not have the same folder structure as your compiling computer. You can use isdeployed in your startup, or anywhere, to conditionally execute code on only target computers or compiling computers. Like
if ~isdeployed
% On development computer -- it's not deployed
newpath = whatever;
savepath(newpath)
else
% On target computer. Don't do anything.
end
Secondly I don't think you should be saving the current path to pathdef.m. It's just not necessary. Why would you want to? I compile and deploy standalone executables all the time and I've never done that. When would that file even ever get read?
In fact I think you should have gotten a compilation warning about using savepath() or cd(), though it's just a warning not a fatal error so it will still complete the compilation for you though the reason for the error may cause an actual error during runtime.
Paths are a tricky thing in deployed standalone executables. I've explained it many times before but basically the "current folder" is not where you think it is. It's not the folder where you placed your .EXE file on the target computer. See the FAQ: https://matlab.fandom.com/wiki/FAQ#Why_can't_my_standalone_compiled_executable_find_my_files?
I think the most likely solution is to explicitly specify the full path name of any file you want to use. The mcc compiler should find any dependent m-files your m-files call so that should not be a problem. However any other kinds of files, like data files, must be fully specified. Do not assume they will be found if you leave off the folder from the filename. Make sure you use fullfile to fully specify the complete path.
If that doesn't solve it, and I've only seen this twice so it's very rare, you can include the "missing" file by using the -a option in your mcc command.
You might also try calling my attached function, GetExecutableFolder, in your app's startup or initialization code (put in your app's m-file, not in your startup.m file).
0 Comments
More Answers (2)
Steven Lord
on 29 Sep 2024
I am fairly certain that the limitation described in the "Do Not Rely on Changing Directory or Path to Control the Execution of MATLAB Files" section on this documentation page is not new and applied to release R2015a (and I think any version of MATLAB Compiler since version 4.0.) Also see the "Packaged Applications Do Not Process MATLAB Files at Run Time" section on that same page.
I think you're going to need to add the path that contains the helper functions to the MATLAB search path before you create the application. That way MATLAB Compiler can include them in the application when it is created.
0 Comments
Vandit
on 29 Sep 2024
Hello Christian,
To resolve the error you're encountering, you can try restoring the default path and rehashing the toolbox cache. Please follow the steps below:
- Before modifying the search path, it is important to take a backup of your 'pathdef.m' file, which can be located by using the command:
>> which -all pathdef
- Ensure you make a safe copy of the file by moving it to a folder outside of your MATLAB path.
- After taking the backup, execute the following commands in the MATLAB Command Window to restore the default MATLAB search path and rehash the toolbox cache.
>> restoredefaultpath
>> rehash toolboxcache
>> sl_refresh_customizations
- After this step, kindly check if the issue occurs again. If the issue is resolved, then you may want to save the new MATLAB search path by executing the following command:
>> savepath
- NOTE: This will remove any custom paths you may have created.The following MATLAB Answers post is an additional resource on how to back them up: https://www.mathworks.com/matlabcentral/answers/166871-how-will-running-the-restoredefaultpath-and-savepath-commands-affect-my-custom-paths-and-how-do
If the issue still persists, feel free to contact MathWorks Technical Support using the following link:
Hope this helps.
See Also
Categories
Find more on Startup and Shutdown in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!