MATLAB Answers


Why do I get an error saying "Undefined function or variable 'matlabrc'" when executing a program that uses a MATLAB-compiled shared library?

MathWorks Support Team さんによって質問されました 2012 年 9 月 10 日
最新アクティビティ Shiyi Chen さんによって コメントされました 2019 年 8 月 27 日 8:24
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'






3 件の回答

回答者: MathWorks Support Team 2012 年 9 月 10 日

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.
If your build process does not involve this process, please follow the troubleshooting steps on the following page of our documentation to help with the resolution of this error.

  0 件のコメント

サインイン to comment.

回答者: Patrick Rollin 2014 年 10 月 15 日

I've had this issue arise from a perfectly working Matlab executable via MCR2013a (v8.1)... and one day it stopped working.
I solved the issue (for Windows 7 64bit) by:
1) deleting the Matlab Runtime Compiler temporary cache folder.
2) re-ran the executable manually to rebuild the required cache folder.
Every time this issue re-arises I simply repeat these 2 steps and I'm back in business.

  3 件のコメント

It WORKS!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Many thanks!
You are a life saver! You have no idea how much time I lost trying to solve this problem...
Many many thanks
Thank you so much!!

サインイン to comment.

回答者: Michael Haitz 2018 年 9 月 27 日

I had the same problem with a dll generated with Matlab Compiler R2015b. After adding matlabrc.m to the m-file list of my compiler command line, the problem seems to be solved.

  2 件のコメント

can you give more information on how you add matlabrc.m to the m-file list of the compiler please? Is this through 'Add a file/folders' to the 'Package' or the 'Shared Resources and Helper Files' within 'Build'?
And is it the matlabrc.m the one from the appropriate MATLAB version such as "C:\Program Files\MATLAB\R2012b\toolbox\local\matlabrc.m"?
Thanks very much
The version from "C:\Program Files\MATLAB\R2012b\toolbox\local\" should be the correct one.
I use the mcc compiler to generate a dll file from my m-files. I just put matlabrc.m in the list of m-files in the command line, e.g.:
"mcc -v -B csharedlib:Main Main.m matlabrc.m file1.m file2.m VerInfoMainXMLS.res"
Then the error disappeared.

サインイン to comment.

Translated by