- 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.
suggested mcc path handling improvements
7 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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:
- Why cannot the command line mcc initialise the path by executing startup.m at least?
- Why are not addpaths protected by default with the condition automatically?
0 comentarios
Respuestas (2)
Titus Edelhofer
el 17 de Dic. de 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
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 comentarios
Titus Edelhofer
el 29 de En. de 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
el 13 de Abr. de 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
Image Analyst
el 29 de En. de 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.
0 comentarios
Ver también
Categorías
Más información sobre Startup and Shutdown en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!