Matlab Engine Problems - matlab

I'm trying to run the basic Matlab enginedemo.cpp in VS2010 on Windows 7 and no matter what I do the code:
`if (!(ep = engOpen(""))) {
fprintf(stderr, "\nCan't start MATLAB engine\n");
return EXIT_FAILURE;
}`
Always errors.
I had both MatlabR2012b and MatlabR2012a installed on my computer but I uninstalled MatlabR2012a and then removed all references to it from my path variable.
I am running x64 MatlabR2012b and I set my VisualC++ Win 32 Console Application.
I also already set the Debugging Environment to: {MatlabRoot}\R2012b\extern\lib\win64\microsoft
C/C++->Additional Include Directories: {MatlabRoot}\R2012b\extern\include
Linker->General->Additional Library Directories: {MatlabRoot}\R2012b\extern\lib\win64\microsoft
Linker->Input->Additional Dependencies: libmx.lib;libmat.lib;libeng.lib
My Matlab version is also registered so that shouldn't be causing the error.
I searched through some of the other stackoverflow questions concerning this and most of them seemed to fix their problems by removing older versions of matlab from the path variable but it hasn't worked for me.

You cannot load 64 bit DLL in 32 bit application. You must make 64 bit console application if you want to work with 64 bit matlab.
You should have {MatlabRoot}\bin\win64 in your PATH (there are libeng.dll and other matlab engine libraries) so your application can find matlab engine libraries during runtime.
execute "matlab /regserver" from command prompt. (to re-register COM components from Matlab 2012a - might not be required, but to be sure)
Hope this helps.

Related

mexopencv needs to re-compile every I restart Matlab

I've recently installed mexopencv for MATLAB on my Windows 7 machine. I'm using MATLAB 2015a 32-bit (on a 64-bit machine). I followed the recommended installation steps (from a number of sources - I had compiler issues to start with) and eventually got it working. The final step in the process is running the following command in MATLAB:
mexopencv.make
This is fine and I've been using it happily ever since. However, whenever I restart MATLAB and run my code which uses mexopencv functions, I get the following:
Error using cv.undistort
Invalid MEX-file 'C:\mexopencv-master\+cv\undistort.mexw32':
C:\mexopencv-master\+cv\undistort.mexw32 is not a valid Win32
application.
After some investigation it seems the only way I can get around this is to run the following every time I restart MATLAB:
mexopencv.make('clean',true)
mexopencv.make
So this is essentially re-compiling the mex files every time I start MATLAB. This takes a good couple of minutes and is a real pain!
Is there some way to get around having to do this each time?
I was facing the same problem (needed to rebuild mexopencv every time). Some people said they solved this problem by setting system PATH but not in my case. Mine was solved by copying all opencv dlls to the same directory those compiled mex files are.

libfaad2.dll is not a valid win32 application - dependency error kernel32.dll

Win7 Service Pack 1
Matlab 2013b
Hello
I am trying to include a libfaad2.dll lib (which I got ready compiled) to Matlab so I can use the functions. I try this with the loadlibrary command.
But I get the error message
libfaad.dll is not a valid win32 application!
from matlab.
A short examination of libfaad2.dll with DependencyWalker (x64 Version) showed that it needs c:\windows\system32\Kernel32.dll. But there is also shown that 2 functions are not available in kernel32.dll
---> So I guess this is not a Matlab Problem
BUT the c:\windows\sysWow64\kernel32.dll includes the desired functions!
How can I tell matlab, or generally, that the libfaad2.dll file should use the sysWow64\kernel32.dll ?
Found a solution: Installing 32 bit version of Matlab and try with this. Worked at first try!
More detailed: Win7 has 2 different folders for system .dlls
C:\windows\system32: Here are all the .dlls for 64-bit software and not for 32!
C:\windows\SysWoW64: WoW64 stands for "Windows on 64-bit Windows", and it contains all the 32-bit binary files required for compatibility, which run on top of the 64 bit Windows.
Using 32-bit version, Matlab will use the SysWoW64 files. And that is the rigth kernel32.dll which contains all the functions needed!

Error: Invalid MEX file, the specified module could not be found

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.
This MathWorks support link suggests two possible reasons to your problem:
You do not have all of the necessary libraries that the MEX-function is dependent upon.
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.
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.
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.
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.

IPPL with Matlab Compiler Runtime (MCR)

I'm trying to deploy an application from Matlab to JAVA.
I use Matlab Builder JA and the Image Processing Toolbox.
I create my jar file from Matlab R2012a with the deploytool on MacOSX.
When I run my JAVA program using this jar on my mac, it's OK, but when I try to run it on a Linux or Windows system, I get the error:
Undefined function or variable 'ipplmex'.
Error in ==> ippl at 48
Error in ==> imrotate>useIPP at 205
Deactivating the use of IPPL with iptsetpref('UseIPPL', false) doesn't fix my problem.
I also have done the exact same work on a Linux environment with Matlab R2011a, and it works on Linux but not on a MacOSX machine with the same error.
If anyone has an idea concerning this IPPL thing when changing OS, that would be great.
Thanks !
Java components created with Builder JA are only cross-platform if they don't depend on platform-specific libraries, such as MEX-files you create, or the IPPL libraries supplied with Image Processing Toolbox.
If you want your Java component to make use of IPPL, I think you'll need to create the Java component once on Mac, once on Linux, once on Windows, and use the version created on the appropriate platform.
ipplmex is a (platform-specific) MEX file that is called by ippl, which is a utility function that checks whether IPPL is available. I can't check this at the moment, but I think it makes that availability check whether or not you've specified that you want to actually use IPPL, via the iptsetpref command. Therefore whether or not you specify that IPPL should be used, there's still a platform-specific MEX-file being called.
Again, I can't check this at the moment, but if you're comfortable with your component not using IPPL, you might try to modify the ippl command to just return zero (indicating that IPPL is not available) without attempting to execute ipplmex. (Make sure to take a copy of your existing ippl.m file before you try any modifications).

Is there a quick method to restore the PATH environment var settings for MATLAB?

I seem to have wiped out my path environment variable a while back. I've been slowly restoring things. I have both MATLAB and the MATLAB compiler installed. DLL's I've created from the MATLAB compiler won't run because they can't find the MATLAB compiler runtime dlls. While I did find the particular files that are my immediate problem. I'm wondering if there is a MATLAB *.bat file or command I can type that will restore my path variable to what it was after MATLAB and the Compiler were installed. I'm hoping to forestall future problems.
In case it's version specific I'm running MATLAB R2010b, I'm running a 32 bit version on a 64 bit machine.
[Edit]
I thought I would add that the path I need for running the compiled version was:
C:\Program Files (x86)\MATLAB\MATLAB Compiler Runtime\v714\runtime\win32
With luck, that one along with the two suggested in the answer will get me back to the original state.
restoredefaultpath might recover your MATLAB installation. Consider the use of startup.m, in order to easily undo changes to your environment.
You want to have these two directories on the PATH (I think the order is important):
C:\Program Files\MATLAB\R2010b\runtime\win32
C:\Program Files\MATLAB\R2010b\bin
Obviously you need to adjust the path to match your setup and architecture (those are on a WinXP 32-bit)
If you have a current software maintenance contract for your MATLAB, it may well be that the easy thing to do is just upgrade to the next version of MATLAB since R2011a is out now (unless there is some compelling reason why you must develop on R2010b. Running the software installer should recreate the default environment for MATLAB. I am, of course, assuming that you have Administrator access on your PC and have permission to install software.