MEX error: "The specified module could not be found."
Show older comments
Hello, I would like to know how to address the following problem: MATLAB gives "The specified module could not be found." when I run a MEX file. Let us divide in a few quick sections my problem to explain it better.
- Original code (stand alone, no MEX): I compiled with the Intel compiler using the following command on the intel oneAPI cmd:
ifort -O3 -Qmkl=parallel test.for -o test
When I run "test.exe", it produces the expected result
[MEX files] I compiled a simple gateway routine that calls the subroutines compiled above. I will show the steps I wook and the solutions I found so far:
- PROMP T1:
mex test.f90
ERROR 1:
"error #7002: Error in opening the compiled module file. Check INCLUDE paths. [MKL_SERVICE]"
SOLUTION 1: Add complementary flag "-Qmkl"
- PROMPT 2
mex COMPFLAGS='$COMPFLAGS -O2 -Qmkl' test.f90
I used the -O2 optimization flag here instead of -O3 (as in the first code snippet) because it seems MATLAB only supports that.
The previous error was solved, but...
ERROR 2:
"LINK : fatal error LNK1104: cannot open file 'mkl_intel_ilp64_dll.lib'"
SOLUTION 2: Include folder with .lib files.
- PROMPT 3
mex COMPFLAGS='$COMPFLAGS -O2 -Qmkl' test.f90 '-LC:\Program Files (x86)\Intel\oneAPI\mkl\2023.2.0\lib\intel64\'
Now, the code does compile (the added path contains the needed .lib files)!
ERROR 3: When I call the function in the form y = test(x), it throws the error:
"The specified module could not be found."
CAUSE OF ERROR 3: I debbuged line by line and found that the problem is when I calls the function pardiso (in the FORTRAN code):
CALL pardiso (pt,... other input arguments
SOLUTION 3 (not working yet): I googled this error, and there are many who had similar problems, but I could not make it work, some of which I show below:
- This person had a similar problem, but without answers
- The same person posted a solution, but it did not work for me (also, he used a previous version of the Intel compiler, with a slightly different syntax)
- The accepted answer to this question suggested using Dependency Walker, which I tried, but my computer is taking over 1 hour to load everything with no success (should I keep trying this method?)
Lastly, I want to mention that I tried also using the flag "-I" to include the "include" folders that contain the "mkl_service" module, in the form:
mex COMPFLAGS='$COMPFLAGS -O2 -Qopenmp -Qmkl' ...
'-IC:\Program Files (x86)\Intel\oneAPI\mkl\2023.2.0\include' ...
'-LC:\Program Files (x86)\Intel\oneAPI\mkl\2023.2.0\lib\intel64' ...
'-IC:\Program Files (x86)\Intel\oneAPI\mkl\2023.2.0\include\intel64\ilp64' ...
'-LC:\Program Files (x86)\Intel\oneAPI\mkl\2023.2.0\lib\intel64\' ...
test.f90
But all yield the same problem (module could not be found).
I apologize for the long question and appreciate any support!
Accepted Answer
More Answers (1)
Swaraj
on 2 Jan 2024
0 votes
Hi Vinicius
This error can be caused when there is a dependency issue.
To identify the missing library dependencies, please download "dependency walker" from the link below http://www.mathworks.com/help/matlab/matlab_external/invalid-mex-file-error.
I suggest using the "dependency walker", it can help in resolving the issue you are facing although it might take some time.
Also, after Simulink generates code and compiles executables for the first time, it makes temporary files for faster compilation the second time. In case it ran successfully once before, try deleting the generated files (YourModel_ert or YourModel_grt, slprj, and the mexed files) and run the process again.
Hope it helps!!
Categories
Find more on MATLAB Compiler 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!