Failure Points and Possible Solutions
How to Use this Section
Use the following list of questions to diagnose some of the
more common issues associated with using MATLAB Compiler software.
Back to Top
Does the Failure Occur During Compilation?
You typically compile your MATLAB code on a development machine,
test the resulting executable on that machine, and deploy the executable
and MATLAB Compiler Runtime (MCR) to a test or customer machine
without MATLAB. The compilation process performs dependency
analysis on your MATLAB code, creates an encrypted archive of your
code and required toolbox code, generates wrapper code, and compiles
the wrapper code into an executable. If your application fails to
build an executable, the following questions may help you isolate
the problem.
Is your selected compiler supported by MATLAB Compiler?
Are error messages produced at compile time?
Did you compile with the verbose flag?
Compilation can fail in MATLAB because of errors encountered
by the system compiler when the generated wrapper code is compiled
into an executable. Additional errors and warnings are printed when
you use the verbose flag as such:
mcc -mv myApplication.m
In this example, -m tells MATLAB Compiler to
create a standalone application and -v tells MATLAB Compiler and
other processors to display messages about the process.
Are you compiling within or outside of MATLAB?
mcc can be invoked from the operating system
command line or from the MATLAB prompt. When you run mcc inside
the MATLAB environment, MATLAB will modify environment variables
in its environment as necessary so mcc will run.
Issues with PATH, LD_LIBRARY_PATH,
or other environment variables seen at the operating system command
line are often not seen at the MATLAB prompt. The environment
that MATLAB uses for mcc can be listed at
the MATLAB prompt. For example:
>>!set
lists
the environment on Windows platforms.
>>!printenv
lists
the environment on UNIX platforms. Using this path allows you to
use mcc from the operating system command line.
Does a simple read/write application such as "Hello
World" compile successfully?
Sometimes applications won't compile because of MEX-file issues,
other toolboxes, or other dependencies. Compiling a helloworld application
can determine if MATLAB Compiler is correctly set up to produce
any executable. For example, try compiling:
function helloworld
disp('hello world')
with:
>>mcc -mv helloworld.m
Have you tried to compile any of the examples in MATLAB Compiler help?
The source code for all examples is provided with MATLAB Compiler
and is located in matlabroot\extern\examples\compiler,
where matlabroot is the root folder of
your MATLAB installation.
Does your code compile with the LCC compiler?
The LCC compiler is a free compiler provided with MATLAB on
Windows. If there are installation or path problems with other system
compilers, you may be able to compile your application with LCC.
Did the MATLAB code compile successfully before this failure?
The three most common reasons for MATLAB code to stop compiling
are:
Upgrading to MATLAB without running mbuild
-setup — Running mbuild -setup is
required after any upgrade to MATLAB Compiler.
A change in the selection of the system compiler
— It is possible to inadvertently change the system compiler
for versions of MATLAB that store preferences in a common folder.
For example, MATLAB 7.0.1 (R14SP1) and MATLAB 7.0.4 (R14SP2)
store their preferences in the same folder. Changing the system compiler
in R14SP1 will also change the system compiler in R14SP2.
An upgrade to MATLAB that didn't include an upgrade
to MATLAB Compiler — The versions of MATLAB Compiler and MATLAB must
be the same in order to work together. It is possible to see conflicts
in installations where the MATLAB installation is local and the MATLAB Compiler installation
is on a network or vice versa.
Are you receiving errors when trying to compile a shared library?
Errors at compile time can indicate issues with either mcc or mbuild.
For troubleshooting mcc issues, see the previous
section on compile time issues. It is recommended that your driver
application be compiled and linked using mbuild. mbuild can
be executed with the -v switch to provide additional
information on the compilation process. If you receive errors at this
stage, ensure that you are using the correct header files and/or libraries
produced by mcc, in your C or C++ driver. For example:
mcc -B csharedlib:hellolib hello.m
produces hellolib.h,
which is required to be included in your C/C++ driver, and hellolib.lib or hellolib.so,
which is required on the mbuild command line.
If you are compiling a driver application, are you using mbuild?
MathWorks recommends and supports using mbuild to
compile your driver application. mbuild is designed
and tested to correctly build driver applications. It will ensure
that all MATLAB header files are found by the C/C++ compiler, and
that all necessary libraries are specified and found by the linker.
Are you trying to compile your driver application using Microsoft Visual Studio or
another IDE?
If using an IDE, in addition to linking to the generated export
library, you need to include an additional dependency to mclmcrrt.lib.
This library is provided for all supported third-party compilers in matlabroot\extern\lib\vendor-name.
Are you importing the correct versions of import libraries?
If you have multiple versions of MATLAB installed on your
machine, it is possible that an older or incompatible version of the
library is referenced. Ensure that the only MATLAB library that
you are linking to is mclmcrrt.lib and that it
is referenced from the appropriate vendor folder. Do not reference
libraries as libmx or libut.
In addition, verify that your library path references the version
of MATLAB that your shared library was built with.
Are you able to compile the matrixdriver example?
Typically, if you cannot compile the examples in the documentation,
it indicates an issue with the installation of MATLAB or your
system compiler. See Libraries for
these examples.
Do you get the MATLAB:I18n:InconsistentLocale Warning?
The warning message
MATLAB:I18n:InconsistentLocale - The system locale setting,
system_locale_name, is different from the user locale
setting, user_locale_name
indicates a mismatch between
locale setting on Microsoft Windows systems. This may affect your
ability to display certain characters. For information about changing
the locale settings, see your operating system Help.
Back to Top
Does the Failure Occur When Testing Your Application?
After you have successfully compiled your application, the next
step is to test it on a development machine and deploy it on a target
machine. Typically the target machine does not have a MATLAB installation
and requires that the MATLAB Compiler Runtime (MCR) be installed.
A distribution includes all of the files that are required by your
application to run, which include the executable, CTF archive and
the MCR.
See Deployment Process, for information on distribution
contents for specific application types and platforms.
Test the application on the development machine by running the
application against the MCR shipped with MATLAB Compiler. This
will verify that library dependencies are correct, that the CTF archive
can be extracted and that all MATLAB code, MEX—files and support
files required by the application have been included in the archive.
If you encounter errors testing your application, the questions in
the column to the right may help you isolate the problem.
Are you able to execute the application from MATLAB?
On the development machine, you can test your application's
execution by issuing !application-name at
the MATLAB prompt. If your application executes within MATLAB but
not from outside, this can indicate an issue with the system PATH variable.
For more information, see Directories Required for Development and Testing.
Does the application begin execution and result in MATLAB or
other errors?
Ensure that you included all necessary files when compiling
your application (see the readme.txt file generated
with your compilation for more details).
Functions that are called from your main MATLAB file are automatically
included by MATLAB Compiler; however, functions that are not explicitly
called, for example through EVAL, need to be included at compilation
using the -a switch of the mcc command.
Also, any support files like .mat, .txt,
or .html files need to be added to the archive
with the -a switch. There is a limitation on the
functionality of MATLAB and associated toolboxes that can be
compiled. Check the documentation to see that the functions used in
your application's MATLAB files are valid. Check the file mccExcludedFiles.log on
the development machine. This file lists all functions called from
your application that cannot be compiled.
Does the application emit a warning like "MATLAB file
may be corrupt"?
See the listing for this error message in MATLAB Compiler for
possible solutions.
Do you have multiple MATLAB versions installed?
Executables generated by MATLAB Compiler are designed to
run in an environment where multiple versions of MATLAB are installed.
Some older versions of MATLAB may not be fully compatible with
this architecture.
On Windows, ensure that the matlabroot/runtime/win32|win64 of
the version of MATLAB in which you are compiling appears ahead
of matlabroot/runtime/win32|win64 of
other versions of MATLAB installed on the PATH environment
variable on your machine.
Similarly, on UNIX, ensure that the dynamic library paths (LD_LIBRARY_PATH on
Linux) match. Do this by comparing the outputs of !printenv at
the MATLAB prompt and printenv at the shell
prompt. Using this path allows you to use mcc from
the operating system command line.
If you are testing a standalone executable or shared library
and driver application, did you install the MCR?
All shared libraries required for your standalone executable
or shared library are contained in the MATLAB Compiler Runtime
(MCR). Installing the MCR is required for any of the deployment targets.
Do you receive an error message about a missing DLL?
Error messages indicating missing DLLs such as mclmcrrt7x.dll or mclmcrrt7x.so are
generally caused by incorrect installation of the MCR. It is also
possible that the MCR is installed correctly, but that the PATH,LD_LIBRARY_PATH,
or DYLD_LIBRARY_PATH variables are set incorrectly.
For information on installing the MCR on a deployment machine, refer
to Working with the MCR.
Caution
Do not solve these problems by moving libraries or other files
within the MCR folder structure. The runtime system is designed to
accommodate different MCR versions operating on the same machine.
The folder structure is an important part of this feature. |
Are you receiving errors when trying to run the shared library
application?
Calling MATLAB Compiler generated shared libraries requires
correct initialization and termination in addition to library calls
themselves. For information on calling shared libraries, see MATLAB Compiler Generated Interface Functions.
Some key points to consider to avoid errors at run time:
Ensure that the calls to mclinitializeApplication and libnameInitialize are
successful. The first function enables construction of MCR instances.
The second creates the MCR instance required by the library named libname.
If these calls are not successful, your application will not execute.
Do not use any mw- or mx-functions
before calling mclinitializeApplication. This includes
static and global variables that are initialized at program start.
Referencing mw- or mx-functions
before initialization results in undefined behavior.
Do not reinitialize (call mclinitializeApplication)
after terminating it with mclTerminateApplication.
The mclinitializeApplication andlibnameInitialize functions
should be called only once.
Ensure that you do not have any library calls after mclTerminateApplication.
Ensure that you are using the correct syntax to call
the library and its functions.
Back to Top
Does the Failure Occur When Deploying the Application to End
Users?
After the application is working on the test machine, failures
can be isolated in end-user deployment. The end users of your application
need to execute MCRInstaller in order to install
the MATLAB Compiler Runtime (MCR) on their machines. The MCR includes
a set of shared libraries that provides support for all features of MATLAB.
If your application fails during end-user deployment, the following
questions in the column to the right may help you isolate the problem.
Is the MCR installed?
All shared libraries required for your standalone executable
or shared library are contained in the MCR. Installing the MCR is
required for any of the deployment targets. SeeWorking with the MCR for complete information.
If running on UNIX or Mac, did you update the dynamic library
path after installing the MCR?
Do you receive an error message about a missing DLL?
Error messages indicating missing DLLs such as mclmcrrt7x.dll or mclmcrrt7x.so are
generally caused by incorrect installation of the MCR. It is also
possible that the MCR is installed correctly, but that the PATH, LD_LIBRARY_PATH,
or DYLD_LIBRARY_PATH variables are set incorrectly.
For information on installing the MCR on a deployment machine, refer
to Working with the MCR.
Caution
Do not solve these problems by moving libraries or other files
within the MCR folder structure. The runtime system is designed to
accommodate different MCR versions operating on the same machine.
The folder structure is an important part of this feature. |
Do you have write access to the directory the application is
installed in?
The first operation attempted by a compiled application is extraction
of the CTF archive. If the archive is not extracted, the application
cannot access the compiled MATLAB code and the application fails.
If the application has write access to the installation folder, a
subfolder named application-name_mcr is
created the first time the application is run. After this subfolder
is created, the application no longer needs write access for subsequent
executions.
Are you executing a newer version of your application?
When deploying a newer version of an executable, both the executable
needs to be redeployed, since it also contains the embedded CTF file.
The CTF file is keyed to a specific compilation session. Every time
an application is recompiled, a new, matched CTF file is created.
As above, write access is required to expand the new CTF file. Deleting
the existing application-name_mcr folder
and running the new executable will verify that the application can
expand the new CTF file.
Back to Top
 | Common Issues | | mbuild |  |
Learn how to build standalone executables and C/C++ shared libraries from MATLAB code.
Get free kit