MATLAB: Do I get warnings when compiling FMINCON and LSQNONLIN in a stand-alone application? Why does FMINCON depend on all these handle graphics functions

aandfminconinlsqnonlinMATLAB Compilerstand-alone

Why do I get warnings when compiling FMINCON and LSQNONLIN in a stand-alone application?
Why does FMINCON depend on all these handle graphics functions? Is there anything else I could try to do to reduce the size of the dll?
I was trying to compile two functions which call many other functions including
a) fmincon
b) lsqnonlin
I was compiling these functions into a library which I could call from Visual Basic.
I compiled the the two functions (foo1 foo2) using the following syntax:
mcc -W lib:mylib -h -L C -t -T link:lib foo1 foo2
None of the routines make any use of graphics. However, when I compile FMINCON with a -h flag (but NO -B sgl) it gives hundreds of warning messages to the effect that if I call any of these
functions there will be a run time error if I do not include the Graphics Library. There are also many other warning messages.

Best Answer

The Optimization Toolbox allows optimization options that graph the result of running the routine. These options use graphics plot commands to show the results. That is why compiling lsqnonlin.m will result in references to these many functions.
There are two recommended ways to work around this limitation:
1. Use the C/C++ graphics library (preferred)
2. Stub out the calls to the MATLAB files involved with the graphics library and disable the associated warning messages.
In order to accomplish the second option, you will need to create a directory containing MATLAB files that are stub versions of the functions in .../toolbox/matlab/graphics, .../toolbox/matlab/graph2d, etc. The MATLAB compiler must be told to examine this directory containing the stub files prior to finding the directory with the actual handle graphics functions in it.
It works like this:
1. Create a directory to contain the stub MATLAB files (hgstubs for example)
2. Populate it with versions of the MATLAB Files from the graphics toolbox with the following definition:
function [varargout] = close( varargin )
error('Graphics functions are not compiled into this application');
These functions will cause an error if they are called in the compiler-generated code.
3. Use the following compilation command from within MATLAB:
mcc -I hgstubs -mvg lsqnonlin -w ...
disable:using_graphics_function
This will cause lsqnonlin to be compiled to produce an error if any of the handle graphics functions are called.
4. In order to use this trick when compiling from the DOS or Unix Shell prompt, you must ensure that the hgstubs directory is on the compiler path prior to the directories containing the graphics functions in MATLAB.
- You must NOT use a saved path in your preferences directory
- You must manually specify the saved path file on the command line after the hgstubs directory.
mcc -I hgstubs -B <mysavedpathfile> -mvg lsqnonlin -w disable:using_graphics_function
5. The specific graphics library functions that will need to be stubbed out for lsqnonlin are:
close, subplot, xlabel, ylabel, legend, and title