11

I have compiled Mex file successfully on my laptop. But when I am running it, it says Invalid mex file 'c:\newfolder\filename.mexw32' The specified module could not be found.

System specification:  
OS: windows 7  
MATLAB 2010a  
Microsoft Visual Studio 2008.  

The same mex file is compiled and run successfully on my PC under XP SP3.

Eitan T
  • 32,037
  • 13
  • 65
  • 103
anand
  • 111
  • 1
  • 1
  • 6

4 Answers4

9

This MathWorks support link suggests two possible reasons to your problem:

  1. You do not have all of the necessary libraries that the MEX-function is dependent upon.
  2. You are running a MEX-file on a different version of MATLAB than it was compiled on.

Either way, to locate the source of this error it says that you need to list all dependent library files and verify their existence in the system you're trying to run the MEX file on, and also recommends the Dependecy Walker as the tool to to do that.

Eitan T
  • 32,037
  • 13
  • 65
  • 103
  • after using Dependency Walker, it shows.. ? CV210d.dll ? cxcore210d.dll ? libmex.dll ? libmx.dll. For all of the above it shows "Error opening file. The system cannot find the file specified(2)." – anand Mar 11 '13 at 13:10
  • @anand This is something related to OpenCV. Do you have this file on your laptop? – Eitan T Mar 11 '13 at 13:11
  • yes, I have all this file on my laptop in C:\OpenCV2.1\bin directory. I don't know what to do after this...Please suggest the solution. – anand Mar 11 '13 at 13:15
  • @anand The question is whether these files are registered in the Windows registry. The building of the MEX file probably works because DLLs are libraries that are dynamically linked during run-time. – Eitan T Mar 11 '13 at 13:21
  • I tried to register the dll files but it shows "cxcore210d.dll was loaded... but its not a valid dll or ocl file". – anand Mar 11 '13 at 14:25
  • @anand Strange. Did you add your OpenCV directory to your system path? – Eitan T Mar 11 '13 at 14:27
  • 1
    Thank you EitanT. When I added 'C:\OpenCV2.1\bin' path in environment variable, the problem got solved. – anand Mar 12 '13 at 07:32
4

Do you you the mex file on another system than the one it is created on?

If so, then you need to install the Microsoft Visual C++ Redistributable on that machine.

Nick
  • 3,103
  • 17
  • 34
  • 1
    No, I compiled mex file on both the machine separately and successfully. But when i tried to run that mexw32 file on my laptop, it shows me error. – anand Mar 11 '13 at 12:54
0

I had this problem also when upgrading from Matlab2010a/VS2008 to Matlab2013a/VS2010.

All my environment variables were sent correctly. A reboot fixed problems with OpenCV dlls not being found, I assume that it was still trying to link to the OpenCV dlls for VS2008 (even though I had changed the path). However still my mex file could not find libmex.dll.

When I installed Matlab2013a, I did not uninstall the old version (in case I wanted to go back). However that was the cause of my problem. Once I uninstalled the old version of Matlab and rebooted again, the problem was gone.

Bull
  • 11,291
  • 9
  • 38
  • 51
0

I had a similar problem. I was only linking against 1 'lib' so I simply copied that lib into the same folder as the mexw64 and it worked.

I have not poked around for the correct place to tell MATLAB to add the lib's real location to whatever path it's looking at.

Mark
  • 1
  • 2