MATLAB: Do I get an error saying “Undefined function or variable ‘matlabrc'” when executing a program that uses a MATLAB-compiled shared library

MATLAB Compiler

I am trying to use a MATLAB-compiled shared library in a C++ program. There are no issues when I use the same code with the libraries compiled using MATLAB Compiler 4.7 (R2007b). However, when I recompile all the MATLAB libraries using MATLAB Compiler 4.9 (R2008b) and then try to execute the same program, the <libName>Initialize() function fails with the following error:
??? Undefined function or variable 'matlabrc'

Best Answer

This change has been incorporated into the documentation in MATLAB Compiler 4.11 (R2009b). For previous releases, read below for any additional information:
Starting MATLAB Compiler 4.8 (R2008a), CTF data is now automatically embedded directly in the C/C++, main and Winmain, shared libraries and standalones by default. In order to override this default functionality, you must compile with the -C 'Do Not Embed CTF Archive By Default 'option.
Since the MATLABRC script is usually included in the CTF archive, you may receive this error if the application is unable to find the CTF archive. Conventionally, some application build procedures strip all binary files involved in the process. If the embedded CTF archives in shared libraries are stripped in this process, the driver application may not be able to find the CTF data during execution.
If your application build process performs such a process, please compile with the -C 'Do Not Embed CTF Archive By Default 'option.
Another workaround here is to delete the CTF extraction folder, and run the EXE again. If the MCR_CACHE_ROOT environment variable is not set, the CTF extraction location can be found at:
C:\Users\[username]\AppData\Local\Temp\[username]\mcrCache[version]
If neither of these resolves the issue, follow these additional troubleshooting steps, previously found at http://www.mathworks.com/help/compiler/deployed-applications.html :
1) Ensure that your application runs in MATLAB (uncompiled) without this error.
2) Ensure that MATLAB starts up without this error.
3) Verify that the generated deployable archive contains a file called matlabrc.m
4) Verify that the generated code (in the * _mcc_component_data.c * file) adds the deployable archive folder containing matlabrc.m to the MATLAB runtime path
5) Delete the *_mcr folder and rerun the application.
6) Recompile the application.
Related Question