MATLAB:mex​:ErrInvali​dMEXFile : Invalid MEX-file: The specified procedure could not be found.

41 次查看(过去 30 天)
I have been facing a vicious Mex runtime error for weeks now that is significantly wasting my time without getting anywhere to resolve it. The error message is in the title of this question. Surprisingly, the compiled Mex files run smoothly under MATLAB 2023b and 2024a, but not under the older versions of MATLAB. Even stranger, I am compiling the Mex file with MATLAB 2022a, and removing all other matlab installations from the paths, and still getting this runtime error with the same MATLAB 2022a, but not with other newer installations.
What could be going wrong? How can I trace the root of this persistent error that sometimes changes to slightly different messages?
  10 个评论
A.B.
A.B. 2024-10-5
Her is the output from mex -setup
MEX configured to use 'Microsoft Visual C++ 2022 (C)' for C language compilation.
Is microsoft CL.exe supported?
Bruno Luong
Bruno Luong 2024-10-5
编辑:Bruno Luong 2024-10-5
"MEX configured to use 'Microsoft Visual C++ 2022 (C)' for C language compilation.=Is microsoft CL.exe supported?"
According to the official link I post above, yes. Also if the compiler can be detected by
mex -setup
then it is supported.

请先登录,再进行评论。

回答(1 个)

Shivam Gothi
Shivam Gothi 2024-10-7
Hello @A.B.,
According to the documentation:
For best results, your version of MATLAB must be the same version that was used to create the MEX file.
MEX files use MATLAB run-time libraries. A MEX file that was created on an earlier version of MATLAB usually runs on later versions of MATLAB. If the MEX file generates errors, recompile the MEX file from the source code.
Now, addressing the issue:
"Even stranger, I am compiling the Mex file with MATLAB 2022a, and removing all other matlab installations from the paths, and still getting this runtime error with the same MATLAB 2022a, but not with other newer installations."
Based on my understanding, I have identified a workaround that might help to find the cause of the issue.
The error message highlighted by you occures in the case when MATLAB cannot find all .DLL files referenced by a MEX file.
Generally, it throws an error as shown below:
Invalid MEX-file mexfilename:
The specified module could not be found.
where mexfilename is the module with the dependency error. This module cannot find its dependent libraries. To resolve this error, find the names of the dependent libraries, and determine if they are present on your system and on the system path.
For windows operating system, you can use “Dependency Walker Utility” for this purpose
Dependency Walker is a tool that tracks and logs files that are accessed when an executable launches. It can also track what files are being called by a DLL or SYS file. It is able to track file registration errors, access violations, invalid page faults or even missing files. It can be downloaded from the website:
To know more about “Dependency walker utility”, refer:
you can also refer to the below MATLAB answer, which addresses somewhat similar issue:
I hope it helps!
  4 个评论
A.B.
A.B. 2024-10-25,4:45
编辑:A.B. 2024-10-25,4:49
Thank you for your responses. I could not fix the problem. The suspicions raised here about compiler compatibility with MEX may be right because the runtime errors only happen with MATLAB R2022b and older, but the mex file works perfectly fine with newer version even on other computers.
However, what is truly bizarre, is that I have an older version of the this MEX file (which calls another DLL just like the newer version). This old MEX file compiles and runs perfectly fine with all MATLAB versions, depite having identical MEX build commands and flags and MATLAB MEX version. I even removed the additional newly included libraries in the new MEX source file, trying to make it as similar as possible to the old MEX file. I compared the build commands word by word and all are the same. Yet, the new MEX file does not run successfully on older MATLAB versions. How could this be possible? The only difference in the build process is for the DLL which both MEX files call. The nex MEX file calls a DLL that has been built with CMake, wehereas the old MEX file calls a DLL that has been built manually by calling the same Fortran compiler that CMake uses on the command line in a windows batch file.
The dependency walker suggested above identifies five errors in the new MEX compiled file. I could not figure out where these errors are, as the software does not offer any readily digestible clues. But regardless, how could these errors cause problems only for the older MATLAB versions?

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Troubleshooting in MATLAB Compiler SDK 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by