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?

465 ビュー (過去 30 日間)
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'

採用された回答

MathWorks Support Team
MathWorks Support Team 2020 年 4 月 30 日
編集済み: MathWorks Support Team 2020 年 4 月 30 日
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.

  0 件のコメント

サインインしてコメントする。

その他の回答 (3 件)

Patrick Rollin
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.
e.g.(C:\Users\[username]\AppData\Local\Temp\[username]\mcrCache[version])
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.
Cheers.

  11 件のコメント

表示 8 件の古いコメント
KAE
KAE 2020 年 4 月 29 日
This needs to be in the documentation, in a location that users can easily find it. I would have been in real trouble without your answer.
Erik Jakobsson
Erik Jakobsson 2020 年 11 月 27 日
Same here. Out of the blue, a whole set of executables stop working. The cache cleaning fixed the issue, but it took a fair while to find, since I naturally assumed I had made some mistake somewhere.

サインインしてコメントする。


Michael Haitz
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 件のコメント

Hazel
Hazel 2019 年 5 月 21 日
Michael,
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
Michael Haitz
Michael Haitz 2019 年 5 月 21 日
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.

サインインしてコメントする。


Image Analyst
Image Analyst 2021 年 1 月 8 日
I was told by tech support that if the MCR extracts to
C:\Users\[username]\AppData\Local\Temp\[username]\mcrCache[version]
like it normally does, then because it's in a "Temp" folder, Windows might go in there on occasion and delete files to free up space. If a file had been deleted, this would give rise to the error. If you delete this folder, then when you run your application again, it will see that the temp folder is missing and will recreate it, restoring any missing files, thus letting it work again.
In the future, to avoid having Windows delete any of these files, you can have your deployed application extract the MCR/CTF to a non-temporary folder that you have write permission to. That way, Windows won't touch the files. To do this you need to set a System level environment variable. So bring up the Environment Variable control panel and make a system level variable called MCR_CACHE_ROOT and set it to some folder you have access to, like
MCR_CACHE_ROOT = C:\Users\Public\Documents\MATLAB\MCR
Your apps will extract the CTF to that folder. It seems each app has its own subfolder under that folder.

  2 件のコメント

Jason
Jason 2021 年 1 月 15 日
OK, so I have added all the files first before compiling.
However, on the target computer I am getting an error loading a specific dll (thats on the target PC)
Error while loading PI_GCS2_DLL_x64.dll.
The PI_GCS2_DLL_x64.dll was assumed to have the following path:
C:\ProgramData\PI\GCSTranslator\PI_GCS2_DLL_x64.dll
The PI MATLAB DRIVER GCS2 either could not find or could not use the "PI_GCS2_DLL_x64.dll".
Make sure you have installed the newest driver for your PI controller and look at the PI MATLAB DRIVER GCS2 Manual in chapter "Troubleshooting" headword "PI GCS2 DLL" for known problems and fixes for problems while loading the PI_GCS2_DLL_x64.dll.
Additional Information: MATLAB itself raised the following error:
The specified module could not be found.
But it is there.
Image Analyst
Image Analyst 2021 年 1 月 16 日
Just before you try to call loadlibrary() with that filename, try this:
if ~isfile(fullFileName)
% File not found.
errorMessage = sprintf('ERROR : DLL file not found:\n%d', fullFileName);
fprintf('%s\n', errorMessage);
uiwait(errordlg(errorMessage));
else
successMessage = sprintf('SUCCESS! I found the DLL file at "%s".', fullFileName);
fprintf('%s\n', successMessage);
uiwait(helpdlg(successMessage));
end
What does the end user see?

サインインしてコメントする。

タグ

タグが未入力です。

製品


リリース

R2008a

Community Treasure Hunt

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

Start Hunting!

Translated by