You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
Invalid MEX-file: The specified module could not be found.
9 views (last 30 days)
Show older comments
Update: I copied the .dll file to the same directory as the mexw64 file, and the script seems to run fine. However, Matlab crashes everytime after this step (crash log posted in the comment section):
INIT STARTEDSetting debug on
matleap version 4.0
Could anyone please advice me on what can be happening here? Thank you so much!
Hello! I am trying to wrap C++ data into Matlab by making a mex-file. I got the following error when I was testing the mex file that I built:
Invalid MEX-file 'C:\Users\...\OneDrive - ...\PROJECT\Leap Motion\matleap\matleap.mexw64': The specified module could not be found.
Error in matleap_version (line 3)
v=matleap(0);
Error in test_matleap (line 12)
[version]=matleap_version;
I checked and .dll file is added to the path when I run the test. Could anyone please give me some advice on what could be the problem? I saw in some previous questions that I should use dependency walker, but that application is just not responding when I try to open a the mex file in it.
14 Comments
Bruno Luong
on 25 Mar 2024
Are you trying too run the mex file on the same computer where it is built?
Julia
on 25 Mar 2024
@James Tursa I was using the code from this github page. The mex file was build by the build.m script, and test was done by running the test_matleap.m script.
Julia
on 25 Mar 2024
------------------------------------------------
MATLAB Log File
------------------------------------------------
--------------------------------------------------------------------------------
Access violation detected at 2024-03-25 18:11:10 +0000
--------------------------------------------------------------------------------
Configuration:
Crash Decoding : Disabled - No sandbox or build area path
Crash Mode : continue (default)
Default Encoding : UTF-8
Deployed : false
Graphics Driver : Uninitialized hardware
Graphics card 1 : NVIDIA ( 0x10de ) NVIDIA GeForce RTX 3070 Version 31.0.15.3770 (2023-10-18)
Java Version : Java 1.8.0_202-b08 with Oracle Corporation Java HotSpot(TM) 64-Bit Server VM mixed mode
MATLAB Architecture : win64
MATLAB Entitlement ID : 1101655
MATLAB Root : C:\Program Files\MATLAB\R2022a
MATLAB Version : 9.12.0.1927505 (R2022a) Update 1
OpenGL : hardware
Operating System : Microsoft Windows 11 Pro for Workstations
Process ID : 6700
Processor ID : x86 Family 6 Model 85 Stepping 7, GenuineIntel
Session Key : 22dd81a2-9966-4b57-9643-c1d614f89467
Window System : Version 10.0 (Build 22631)
Fault Count: 1
Abnormal termination:
Access violation
Current Thread: 'MCR 0 interpreter thread' id 12640
Register State (from fault):
RAX = 0000000000000000 RBX = 0000000000000000
RCX = 00000000ffffffff RDX = 000000994a3fa320
RSP = 000000994a3f9bf0 RBP = 000000994a3f9cf0
RSI = 0000000000000001 RDI = 000000994a3fa320
R8 = 0000000000000001 R9 = 000000994a3fadb8
R10 = 00007ffe408f1df0 R11 = 000000994a3fa210
R12 = 000000994a3fadb8 R13 = 000002665459b950
R14 = 000002664c396270 R15 = 000000994a3fadb8
RIP = 00007ffe408f1156 EFL = 00010202
CS = 0033 FS = 0053 GS = 002b
Stack Trace (from fault):
[ 0] 0x00007ffe408f1156 C:\Users\DRI CR&T\Desktop\matleap\matleap\matleap.mexw64+00004438
[ 1] 0x00007ffe408f1f64 C:\Users\DRI CR&T\Desktop\matleap\matleap\matleap.mexw64+00008036 mexFunction+00000372
[ 2] 0x00007ffe6bc78149 C:\Program Files\MATLAB\R2022a\bin\win64\libmex.dll+00557385 mexfile::Inspector::needs_upgrade+00027305
[ 3] 0x00007ffe6bc7bbf2 C:\Program Files\MATLAB\R2022a\bin\win64\libmex.dll+00572402 MexRetrieveVersion+00011778
[ 4] 0x00007ffe6bc7bf17 C:\Program Files\MATLAB\R2022a\bin\win64\libmex.dll+00573207 MexRetrieveVersion+00012583
[ 5] 0x00007ffe6bc5a2f2 C:\Program Files\MATLAB\R2022a\bin\win64\libmex.dll+00434930 mexUnlock+00016914
[ 6] 0x00007ffe6bb5c254 bin\win64\pgo\m_dispatcher.dll+00639572 Mfh_file::dispatch_file_common+00000168
[ 7] 0x00007ffe6bb5ba16 bin\win64\pgo\m_dispatcher.dll+00637462 Mfh_error::lookup+00002546
[ 8] 0x00007ffe6bb5c1a5 bin\win64\pgo\m_dispatcher.dll+00639397 Mfh_file::dispatch+00000045
[ 9] 0x00007ffe6b791324 C:\Program Files\MATLAB\R2022a\bin\win64\libmwlxemainservices.dll+00332580 mwboost::archive::codecvt_null<wchar_t>::do_always_noconv+00071588
[ 10] 0x00007ffe6b79f720 C:\Program Files\MATLAB\R2022a\bin\win64\libmwlxemainservices.dll+00390944 mwboost::archive::codecvt_null<wchar_t>::do_always_noconv+00129952
[ 11] 0x00007ffe68131721 C:\Program Files\MATLAB\R2022a\bin\win64\m_lxe.dll+05510945 MathWorks::lxe::ReadOnlyXvaluePtr::operator=+00006097
[ 12] 0x00007ffe68133208 C:\Program Files\MATLAB\R2022a\bin\win64\m_lxe.dll+05517832 MathWorks::lxe::ReadOnlyXvaluePtr::operator=+00012984
[ 13] 0x00007ffe680879b8 C:\Program Files\MATLAB\R2022a\bin\win64\m_lxe.dll+04815288 MathWorks::lxe::printLxeProfStatsForFeature+00279032
[ 14] 0x00007ffe6809fc99 C:\Program Files\MATLAB\R2022a\bin\win64\m_lxe.dll+04914329 MathWorks::lxe::printLxeProfStatsForFeature+00378073
[ 15] 0x00007ffe67e9bbab C:\Program Files\MATLAB\R2022a\bin\win64\m_lxe.dll+02800555 MathWorks::lxe::LXEConstants::IsIfElse+00522971
[ 16] 0x00007ffe67ea0074 C:\Program Files\MATLAB\R2022a\bin\win64\m_lxe.dll+02818164 MathWorks::lxe::LXEConstants::IsY+00012660
[ 17] 0x00007ffe67e9d601 C:\Program Files\MATLAB\R2022a\bin\win64\m_lxe.dll+02807297 MathWorks::lxe::LXEConstants::IsY+00001793
[ 18] 0x00007ffe67ea11b5 C:\Program Files\MATLAB\R2022a\bin\win64\m_lxe.dll+02822581 MathWorks::lxe::LXEConstants::IsY+00017077
[ 19] 0x00007ffe67ea1463 C:\Program Files\MATLAB\R2022a\bin\win64\m_lxe.dll+02823267 MathWorks::lxe::LXEConstants::IsY+00017763
[ 20] 0x00007ffe67ea0db8 C:\Program Files\MATLAB\R2022a\bin\win64\m_lxe.dll+02821560 MathWorks::lxe::LXEConstants::IsY+00016056
[ 21] 0x00007ffe67e9cda6 C:\Program Files\MATLAB\R2022a\bin\win64\m_lxe.dll+02805158 MathWorks::lxe::LxeTypes::GetTypeXvalueOf+00000598
[ 22] 0x00007ffe67f6b3e5 C:\Program Files\MATLAB\R2022a\bin\win64\m_lxe.dll+03650533 MathWorks::lxe::SetEngineImplUnlinkFlagForAllCallsOnStack+00043317
[ 23] 0x00007ffe67f6ef60 C:\Program Files\MATLAB\R2022a\bin\win64\m_lxe.dll+03665760 MathWorks::lxe::SetEngineImplUnlinkFlagForAllCallsOnStack+00058544
[ 24] 0x00007ffe6b85f830 C:\Program Files\MATLAB\R2022a\bin\win64\libmwlxemainservices.dll+01177648 FeatureTestObservableWorkspace+00186352
[ 25] 0x00007ffe6b7cbc7e C:\Program Files\MATLAB\R2022a\bin\win64\libmwlxemainservices.dll+00572542 mwboost::archive::detail::pointer_oserializer<mwboost::archive::xml_oarchive,MathWorks::lxe::PreLineExecutionEvent>::save_object_ptr+00069966
[ 26] 0x00007ffe6b7cd5bf C:\Program Files\MATLAB\R2022a\bin\win64\libmwlxemainservices.dll+00579007 mwboost::archive::detail::pointer_oserializer<mwboost::archive::xml_oarchive,MathWorks::lxe::PreLineExecutionEvent>::save_object_ptr+00076431
[ 27] 0x00007ffe6b828cf6 C:\Program Files\MATLAB\R2022a\bin\win64\libmwlxemainservices.dll+00953590 mwboost::archive::detail::pointer_oserializer<mwboost::archive::xml_oarchive,MathWorks::lxe::PreLineExecutionEvent>::save_object_ptr+00451014
[ 28] 0x00007ffe6b82aca7 C:\Program Files\MATLAB\R2022a\bin\win64\libmwlxemainservices.dll+00961703 mwboost::archive::detail::pointer_oserializer<mwboost::archive::xml_oarchive,MathWorks::lxe::PreLineExecutionEvent>::save_object_ptr+00459127
[ 29] 0x00007ffe6b82a050 C:\Program Files\MATLAB\R2022a\bin\win64\libmwlxemainservices.dll+00958544 mwboost::archive::detail::pointer_oserializer<mwboost::archive::xml_oarchive,MathWorks::lxe::PreLineExecutionEvent>::save_object_ptr+00455968
[ 30] 0x00007ffe73f625b9 C:\Program Files\MATLAB\R2022a\bin\win64\libmwbridge.dll+00140729 mnGetPrompt+00025257
[ 31] 0x00007ffe6bd675c6 C:\Program Files\MATLAB\R2022a\bin\win64\iqm.dll+00488902 iqm::Iqm::instance+00001190
[ 32] 0x00007ffe6bdb6a60 C:\Program Files\MATLAB\R2022a\bin\win64\iqm.dll+00813664 iqm::UserEvalPlugin::execute+00001360
[ 33] 0x00007ffe6bd89882 C:\Program Files\MATLAB\R2022a\bin\win64\iqm.dll+00628866 iqm::Iqm::setupIqmFcnPtrs+00094722
[ 34] 0x00007ffe6bd933ca C:\Program Files\MATLAB\R2022a\bin\win64\iqm.dll+00668618 iqm::Iqm::setupIqmFcnPtrs+00134474
[ 35] 0x00007ffe6bd5af4b C:\Program Files\MATLAB\R2022a\bin\win64\iqm.dll+00438091 iqm::Iqm::create+00009067
[ 36] 0x00007ffe73f52de5 C:\Program Files\MATLAB\R2022a\bin\win64\libmwbridge.dll+00077285 ioReadLine+00000501
[ 37] 0x00007ffe73f52bb5 C:\Program Files\MATLAB\R2022a\bin\win64\libmwbridge.dll+00076725 ioReadLine+00000165
[ 38] 0x00007ffe73f62970 C:\Program Files\MATLAB\R2022a\bin\win64\libmwbridge.dll+00141680 mnGetCommandLineBuffer+00000288
[ 39] 0x00007ffe73f62e02 C:\Program Files\MATLAB\R2022a\bin\win64\libmwbridge.dll+00142850 mnParser+00000466
[ 40] 0x00007ffe6bec7226 C:\Program Files\MATLAB\R2022a\bin\win64\mcr.dll+00422438 mcr_set_enableReadingFromStdin+00013622
[ 41] 0x00007ffe6be789a3 C:\Program Files\MATLAB\R2022a\bin\win64\mcr.dll+00100771 mcrFunctionSignature::set_signature+00079731
[ 42] 0x00007ffe6be96230 C:\Program Files\MATLAB\R2022a\bin\win64\mcr.dll+00221744 mwboost::archive::codecvt_null<wchar_t>::`default constructor closure'+00017584
[ 43] 0x00007ffe6bdb1e0a C:\Program Files\MATLAB\R2022a\bin\win64\iqm.dll+00794122 iqm::PackagedTaskPlugin::execute+00000074
[ 44] 0x00007ffe6bec19ad C:\Program Files\MATLAB\R2022a\bin\win64\mcr.dll+00399789 services::lmgr::exception::LicensingStartupException::~LicensingStartupException+00006861
[ 45] 0x00007ffe6bd89882 C:\Program Files\MATLAB\R2022a\bin\win64\iqm.dll+00628866 iqm::Iqm::setupIqmFcnPtrs+00094722
[ 46] 0x00007ffe6bd5bd86 C:\Program Files\MATLAB\R2022a\bin\win64\iqm.dll+00441734 iqm::Iqm::create+00012710
[ 47] 0x00007ffe6bd5b472 C:\Program Files\MATLAB\R2022a\bin\win64\iqm.dll+00439410 iqm::Iqm::create+00010386
[ 48] 0x00007ffe6beb072c C:\Program Files\MATLAB\R2022a\bin\win64\mcr.dll+00329516 mcrInstantiationError::operator=+00010380
[ 49] 0x00007ffe6beb1165 C:\Program Files\MATLAB\R2022a\bin\win64\mcr.dll+00332133 mcrInstantiationError::operator=+00012997
[ 50] 0x00007ffe6beae930 C:\Program Files\MATLAB\R2022a\bin\win64\mcr.dll+00321840 mcrInstantiationError::operator=+00002704
[ 51] 0x00007ffecf9b85da C:\Program Files\MATLAB\R2022a\bin\win64\mwboost_thread-vc142-mt-x64-1_75.dll+00034266 mwboost::thread::swap+00000074
[ 52] 0x00007ffef4919363 C:\WINDOWS\System32\ucrtbase.dll+00168803 recalloc+00000163
[ 53] 0x00007ffef5fb257d C:\WINDOWS\System32\KERNEL32.DLL+00075133 BaseThreadInitThunk+00000029
[ 54] 0x00007ffef704aa58 C:\WINDOWS\SYSTEM32\ntdll.dll+00371288 RtlUserThreadStart+00000040
This error was detected while a MEX-file was running. If the MEX-file
is not an official MathWorks function, please examine its source code
for errors. Please consult the External Interfaces Guide for information
on debugging MEX-files.
James Tursa
on 25 Mar 2024
Edited: James Tursa
on 25 Mar 2024
Can you try a manual build? E.g., something like:
mex matleap.cpp LeapConnection.cpp LeapSDK.lib -R2018a
where all the required files are in the same directory. Or maybe
mex('matleap.cpp','LeapConnection.cpp','(full directory path)/LeapSDK.lib','-R2018a')
Bruno Luong
on 25 Mar 2024
@Julia "This error was detected while a MEX-file was running. If the MEX-file"
I though the MEX file cannot be run since "Invalid MEX-file" was reported orginally, now it runs and crashes? What have you changed?
James Tursa
on 25 Mar 2024
Edited: James Tursa
on 25 Mar 2024
@Bruno Luong It looks like the mex routine compiles and starts, and this is a run-time error. E.g., there is maybe some output to the screen before crashing (is this coming from the mex routine?). Can't find a routine in a DLL or LIB file, etc. Could be the result of linking with wrong library files? Or maybe a compiler setting is incorrect?
Julia
on 25 Mar 2024
@James Tursa Thank you so, so much for your help! I will try it once I get access to my working computer tomorrow. Do you mean that, instead of
% create the mex command line
fn='matleap.cpp LeapConnection.cpp';
fprintf('Compiling %s\n',fn);
cmd=['mex',...
' -R2018a',...
' -I./LeapSDK/include ',...
libdir_switch,...
' -lLeapC ',...
fn];
fprintf('Evaluating "%s"\n',cmd)
I should do the following?
mex('-R2018a',' -I./LeapSDK/include ','-L./LeapSDK/lib/x64','(full directory path)/LeapSDK.lib',' -lLeapC ','matleap.cpp','LeapConnection.cpp')
And yes, I am getting some output before the Matlab crash. I get
INIT STARTEDSetting debug on
matleap version 4.0
Julia
on 25 Mar 2024
@Bruno Luong Your help is much appreciated!
The only change I made was copying the LeapC.dll file from C:\Users\...\matleap\LeapSDK\lib\x64 to C:\Users\...\matleap, which is the same folder where the matleap.mexw64 file locates.
Bruno Luong
on 26 Mar 2024
Edited: Bruno Luong
on 26 Mar 2024
But that is the crucial change, by copying the dll file, now your MEX file can load the DLL and starts correctly.
Now why it crashes. This is entirely diffrent issue. You have to ask the author or debug yourself the mex file. Unless if it crashes inside the DLL and LIBRARY without the source code available, the it is not possible to debug.
The error message suggests
"If the MEX-file is not an official MathWorks function, please examine its source code for errors. Please consult the External Interfaces Guide for information on debugging MEX-files."
The cause of the bug can be anythihg, I doubt anyone can help you from now.
In the MEX command you haven't provide the value of "libdir_switch" hard to tell if the roll standalone mex command does the same.
Julia
on 27 Mar 2024
@James Tursa Hi James, I am trying to manually build the mex file, and I noticed that the original code was using R2018a compatbility, which I think could be the problem.
fn='matleap.cpp LeapConnection.cpp';
fprintf('Compiling %s\n',fn);
cmd=['mex',...
' -R2018a',...
' -I./LeapSDK/include ',...
libdir_switch,...
' -lLeapC ',...
fn];
fprintf('Evaluating "%s"\n',cmd)
However, when I changed '-R2018a' to '-R2023b", which is the version I am using, I received an error that
Error using mex
Unknown MEX argument '-R2023b'.
Could you please let me know what may be the issue here?
Bruno Luong
on 27 Mar 2024
Edited: Bruno Luong
on 27 Mar 2024
The purspose of -R2018a switch is to cope with change of internal storage: interleaved complex number storage and accesory using some mxGetxxxx API, This major change of internal happens in R2018a. however your mex compile without the flag, so those API are not used.
There is not such switch as -R2023b.
You should add -R2018a switch if you use direct mex command. But I believe the effect would be only accelerate the code execution, since no data copying (hidden to user) if mxGetData, mxGetPr, mxGetPi is performed in theory.
Julia
on 9 Apr 2024
Solution found! The problem was not with the code. It seems like my recording device was not activated when I was running the script. Matlab probably was crashing because it cannot find the frames it was supposed to get. Huge thanks to James and Bruno for your help!
Answers (0)
See Also
Categories
Find more on MATLAB Compiler in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom(English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)