Standalone compiled with Matlab compiler doesn't work on other computers.

I have compiled a .exe file using Matlab compiler which works fine on my computer, but when I try to run it on any other computer it crashes on startup. I have made sure that the target machine has the correct version of MCR and I have followed the directions listed here for debugging:
Furthermore, when I tried using DependencyWalker as step 4 from above, I get the same results from the following page, but none of the answers there have solved my problem.
If anyone could point me in the right direction it would be greatly appreciated!

4 Comments

A couple of years ago, I had a similar problem which was caused by something in the startup file on my development computer. Unfortunately I don't remember exactly what it was (possibly a 'cd' command), but then I removed it and everything worked fine.
Thank you for your reply. I think that the startup.m file may be the source of my problem as well, but I have yet to solve the problem. The startup file has one line (load matlab.mat) but Matlab is unable to find this file on startup, perhaps the cd command you speak of is a switch to the directory containing this file. Does any of this sound familiar?
I know nothing about compilation issues, but...
A single-line startup.m file with a load matlab.mat sounds like the default startupsav.m example file, which is designed to be paired with the example finishsav.m example. These examples work to save the working environment to a .mat file on closing Matlab, and reload it on startup.
It sounds like this particular startup file is not really being used on this machine. So I'd recommend just deleting it. The startup file is only needed if you want to custom configure details every time you run Matlab. (And if you do have custom instructions, such as cd-ing to a specific working directory, you'd better be sure all code you run, compiled or not, is robust to that.)
Thank you Kelly. You are correct in asserting that the startup.m file that I use is just the default startupsav.m file saved with a different name. Since it is not necessary to include startup.m you have cast some doubt on my thought that that was the problem. In my search I did look through matlabrc.m and found a number of uses of isdeployed, so perhaps one of those calls is the reason why the program works on my development computer but nowhere else?

Sign in to comment.

Answers (2)

You can put it in a try catch
try
load('matlab.mat');
catch
end
Or you could check if the application is deployed
if ~isdeployed
load('matlab.mat');
end
Of course if the file is essential then you'll have to find it. Try specifying the full path where it's known to live.

4 Comments

As Kelly pointed out above, the matlab.mat file is not necessarily essential to the operation of the program, it is only included in startupsav.m as an example of loading and saving environment data upon startup and shut down. Upon start up, matlabrc.m calls startup.m so this is why I believe that the problem may lie there in one of the calls to isdeployed.
Your startup.m file will run on your target computer first before your actual code runs. Using try catch will prevent the program from completely vanishing if there is an error. If your startup.m file has code that you do want to run in your development environment but not in the standalone program deployed to your target computer/end user, you can wrap stuff in it like this:
if isdeployed
% Code that runs only in standalone program
else
% Code that runs only in development environment (MATLAB)
end
% Code after that (i.e. down here) will run in both environments.
Thank you for your insight Image Analyst. I don't intend for there to be any differences between the development and release versions of my program, so there is no reason for me to use a startup.m file outlining the differences. However, matlabrc.m runs on startup and there are a number of try-catch blocks in that code, yet I don't get any debug messages on start up. If I run it from a console all I get is an instance of Visual Studio asking if I want to debug, but there is no useful information there.
It's hard to help if I don't have your executable or the source code. If you've done everything in the FAQ then you might have to call the Mathworks. They can see and drive your computer to get it figured out. However in my experience, most compiled problems are due to the file not being on the search path or in the expected folder. Make sure you make your program robust by using "if !exist(filename, 'file')" before any line of code where you try to use a file.

Sign in to comment.

I found the solution to my problem. I was using 64-bit Matlab to compile my program but I was installing the 32-bit version of the MCR on my target computer. I installed the 64-bit MCR and it works fine.

1 Comment

Yes. That's number 10 on the FAQ list I referred you to. So, could you go ahead and "Accept" my answer above? Thanks in advance.

Sign in to comment.

Categories

Asked:

on 7 Mar 2018

Commented:

on 13 Mar 2018

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!