Clear Filters
Clear Filters

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

65 views (last 30 days)
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 Comments
A.B.
A.B. on 5 Oct 2024 at 0:32
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 on 5 Oct 2024 at 5:01
Edited: Bruno Luong on 5 Oct 2024 at 7:44
"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.

Sign in to comment.

Answers (1)

Shivam Gothi
Shivam Gothi about 3 hours ago
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!
  3 Comments
Shivam Gothi
Shivam Gothi 23 minutes ago
what I understand from the question is, the compiled MEX file is running with more recent version of MATLAB, but while compiling it using MATLAB R2022a, it is giving error. That's why I suspected that the appropriate DLL file might have been missing or corrupted or not properly located on the path while trying out MATLAB R2022a.

Sign in to comment.

Categories

Find more on Troubleshooting in MATLAB Compiler SDK in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!