"File is not a mex file" error despite the settings seeming correct

8 views (last 30 days)
I am trying to follow the Matlab examples on using mex. I first run
copyfile(fullfile(matlabroot,"extern","examples","mex","yprime.c"),".","f")
and this works, copying the file. I then run
mex yprime.c
which gives me the output
Building with 'MinGW64 Compiler (C)'.
Error using mex
'yprime.mexw64' is not a MEX file. For more information, see File is not a MEX file.
I have ensured that I am using the correct version of the compiler (6.3.0). I am using a 64-bit operating system with 64-bit MATLAB, and running
mexext
returns mexw64 as expected. So I am not sure what the issue could be. I have looked in the "see File is not a MEX file" section of the help and it did not help me resolve the issue.
  1 Comment
dpb
dpb on 4 Oct 2024
There apparently is at least one other way to generate the message than just the wrong extension...
I haven't tried mex'ing anything in years since they quit supporting any Fortran compiler other than Intel...

Sign in to comment.

Accepted Answer

Elliott
Elliott on 7 Oct 2024
Issue is resolved. The filepath for an executeable is longer than allowed by administration on my laptop and so it fails to execute correctly. Performing the same operations with a shorter filepath worked with no issues.

More Answers (1)

Shivam Gothi
Shivam Gothi on 7 Oct 2024
Hello @Elliott
I have executed the code you provided in MATLAB R2022b, without encountering any errors. However, I have identified a few workarounds that might help resolve the issue.
Cause of the error:
If MATLAB cannot find all .DLL files referenced by a MEX file, it cannot load the MEX file. MATLAB displays the following error message:
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”.
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:
Refer to the below documentation to get more detailed explanation:
To know more about “Dependency walker utility”, refer:
you can also refer to the below MATLAB answer, which addresses the similar issue:
I hope it helps!
  1 Comment
Elliott
Elliott on 7 Oct 2024
Hi Shivam,
Thanks for the answer. There are no specific ones missing for the files I am trying to compile which is unfortunate.
I think the error you mentioned is a slightly different one to the one I am getting. I am getting
Error using mex
'yprime.mexw64' is not a MEX file. For more information, see File is not a MEX file.
rather than an error about missing dlls.

Sign in to comment.

Products


Release

R2022b

Community Treasure Hunt

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

Start Hunting!