- 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
조회 수: 6 (최근 30일)
이전 댓글 표시
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
답변 (2개)
Titus Edelhofer
2012년 12월 17일
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
Titus Edelhofer
2013년 1월 29일
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
2022년 4월 13일
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
2013년 1월 29일
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
참고 항목
카테고리
Help Center 및 File Exchange에서 Startup and Shutdown에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!