2

I am trying to figure how to use the Matlab engine so I can use C++ GUI with matlab function however I am having some trouble trying to figure out how to use the MATLAB engine classes. The first thing I did was try to run their examples after a bit of trying I go this error upon a successful build, "The application was unable to start correctly 0xc000007b" How do I fix this and will this? In addition I attempted to run my own code too, even though it was simple it still did not work.

Note: a did a couple of searches and all I found was that there is a simmilar porblem with adobe cs5, Also I ran dependency walker and it said it did not find any dependencies on libeng.dll Here is what I ran;

    int main(){
Engine *ep;
ep = engOpen(NULL);
engEvalString(ep, "3+4");
return 0; }

The system is Windows 7 enterprise 64 bit

Jav_Rock
  • 22,059
  • 20
  • 123
  • 164
Treesrule14
  • 711
  • 7
  • 14
  • I don't see any error handling. – Ben Voigt Jun 23 '11 at 17:48
  • I had the same problem when I ran their code which had error handeling. – Treesrule14 Jun 23 '11 at 17:56
  • @Treesrule: So what errors did you get before the crash occurred? – Ben Voigt Jun 23 '11 at 18:45
  • @Treesrule: Then I don't think you have proper error handling. Does the other example code check the return value from `engOpen`? If you add `fputs(stderr, "Program starting\n");` as the very first line of `main`, do you see that output? – Ben Voigt Jun 23 '11 at 19:53
  • fputs did not work for some reason but I used cout and that did not show up, also I changed the code so it checks to make sure engopen works – Treesrule14 Jun 23 '11 at 20:19
  • @Treesrule: Ok, it sounds as if the program isn't loading the C++ runtime libraries correctly. Is this the same computer where you compiled it or a different one? – Ben Voigt Jun 23 '11 at 20:39
  • @Treesrule: BTW, to use `fputs` you just need `#include `. But `cerr` would work too. I didn't want to suggest `stdout`/`cout` because those are buffered and output can be lost when the program crashes. – Ben Voigt Jun 23 '11 at 21:32
  • So if you write `#include int main(int argc, char** argv) { fputs(stderr, "Program starting.\n"); return 0; }` (comment out the MatLab stuff) does the program run right? Then try uncommenting the MatLab stuff and putting it inside `if (argc == 1000) { matlab stuff }`, so the compiler has to include the code but it won't actually run. Does that run or still crash? – Ben Voigt Jun 23 '11 at 21:34
  • My computer does not recognize stderr – Treesrule14 Jun 24 '11 at 15:13
  • @Treesrule: Sorry, my mistake. `stderr` is supposed to be the last parameters to `fputs`, not the first, like [this](http://ideone.com/GK4a8), that'll fix a type mismatch. If `stderr` is totally undefined, it means you didn't `#include `. – Ben Voigt Jun 24 '11 at 16:35
  • Okay so I ran the code with fputs, it runs and appears without the engine code but once I include the MATLAB code it does not work – Treesrule14 Jun 27 '11 at 13:11
  • @Treesrule: So even if the calls to matlab are inside an if that doesn't run, the program won't start? Sounds like a dependency DLL load problem, but you said there are no imports from that DLL? – Ben Voigt Jun 27 '11 at 16:21
  • I ran dependency walker on libeng.dll and got this as output; Error: At least one required implicit or forwarded dependency was not found. Warning: At least one delay-load dependency module was not found. Warning: At least one module has an unresolved import due to a missing export function in a delay-load dependent module. – Treesrule14 Jun 27 '11 at 18:49
  • @TreesruleL Dependency Walker also tells you which DLL wasn't found. It'll have an exclamation mark or similar error symbol next to it, both in the dependency tree (upper left) and the module list (below). You probably need to adjust your path or copy some MatLab DLLs into the application directory (of course copying is only allowed if you already have a MatLab license for the computer). – Ben Voigt Jun 27 '11 at 22:44
  • So I tried it on another computer and it worked. Then I tried to add the files to the appropriate directory and I got an error same kind but with some different errors; "The program '[3916] NewAttempt.exe: Native' has exited with code -1073741701 (0xc000007b)." So now the question is where should I be putting the files, all of the other files seems to be in c:\windows\systen32 so I put them there I do not think that helped though. – Treesrule14 Jun 28 '11 at 17:40
  • @treesrule: I wonder if you have a 32-bit/64-bit mismatch (have both but the wrong one is found first, while the other computer has only the right one). Dependency Walker should identify these, although you might have to use its profiler mode, and that doesn't always work right with .NET programs. If this isn't .NET, you should be in great shape. Run Dependency Walker, choose "Start Profiling" from the menu, and take note of the error which appears. – Ben Voigt Jun 28 '11 at 23:56

1 Answers1

3

This error is likely due to incorrect installation or multiple installations of Matlab on your machine. Check your Windows %PATH% environment variable by opening a command window and typing

echo %PATH%

When it contains references to more than a single Matlab installation, edit %PATH% and remove all of them except the reference to the installation you are going to use with your program. The following dlls must be in your %PATH%: libeng.dll and libmx.dll. Don't copying these dlls to a system directory -- change your %PATH% instead.

Make sure to execute this command on the command line to register the Matlab engine with Windows COM.

matlab /regserver
user244795
  • 698
  • 6
  • 14