suggested mcc path handling improvements

6 views (last 30 days)
Balint Takacs
Balint Takacs on 17 Dec 2012
Commented: Jed on 13 Apr 2022
When trying to compile stuff, after lots of suffering we concluded that:
If compiling from the command line, all MATLAB paths has to be added manually with -I, otherwise files are not found.
To run the same compiled code, all MATLAB paths has to be removed manually from execution by protecting addpath instructions with 'if ~(ismcc isdeployed)', otherwise files are not found.
If we are not wrong in these conclusions, the lesson learnt is that currently mcc path handling is an inconsistent mess. Two obvious questions arise:
  1. Why cannot the command line mcc initialise the path by executing startup.m at least?
  2. Why are not addpaths protected by default with the condition automatically?

Answers (2)

Titus Edelhofer
Titus Edelhofer on 17 Dec 2012
Hi Balint,
some comments, although not necessarily answering your questions (let's see).
First: avoid addpath in the MATLAB code itself that you run. I would suggest either
  • Use pathtool for permanent changes to the path
  • Put addpath into your startup.m (important: put the calls to addpath inside a block protected by "if isdeployed" ...)
  • Write a function setPath.m somewhere doing the same that you call before calling your application.
This way you don't have to add the paths manually but you have added them to run the application in MATLAB (and btw for the compilation process).
Second: this way you don't have to do anything for the compiled application, because it has automatically the correct paths.
Titus
  3 Comments
Titus Edelhofer
Titus Edelhofer on 29 Jan 2013
Hi Balint,
I guess I misinterpreted "from commandline" with "from command window". You are referring to from the operation system command line? If this is the case, just for curiosity, why are you calling mcc from command line instead of from within MATLAB?
Titus
Jed
Jed on 13 Apr 2022
fwiw, I always call it from the command line.... mostly for convenience.
I use mcc in the same way as I would use gcc

Sign in to comment.


Image Analyst
Image Analyst on 29 Jan 2013
Is there some background for what you're saying, like a post I missed or something? Because I'm not sure I agree with everything you're saying. I think you don't understand the crazy way that standalone MATLAB executables work. Perhaps you should review this section of the FAQ: http://matlab.wikia.com/wiki/FAQ#Why_can.27t_my_standalone_compiled_executable_find_my_files.3F
To answer your questions, your startup.m file does get executed when your compiled app runs. Therefore you can have stuff in there that gets run differently depending on whether isdeployed is true or not. This is what I do.
Regarding addpath, if you're adding a relative path, it gets added to that secret folder where the real executable lives (see the FAQ), so it may not get added to where you think it does, which can be a pain if you load the main executable folder with subfolders and other files (like mat files, Excel workbooks, etc.) because you think it should find them but it won't because it's not looking there.
Anyway, I think you're best off avoiding addpath, genpath, rmpath in your code and make sure you deal with absolute folder names and absolute filenames that you know exist, and verify exist with exist(). Don't ever rely on the path being something unless you specified absolute paths, not relative paths.

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!