How to fix error in Calling MATLAB Functions from C++?

hi i want to execute the first example of "Call MATLAB Functions from C++" that use MATLAB gcd function. when i run the code it doesn't work and show the below error.
how can i fix it?

6 Comments

Did you try using Dependency Walker or equivalent https://www.raymond.cc/blog/check-what-dll-or-ocx-dependency-files-is-needed-for-a-software/
yes i tried Dependency Walker. the problem is VB need to access .DLL of .lib files. how can i get them?
I do not do much Windows work but my memory is that .lib files are static linked and so there is no dll for them.
It seems that there are several issues here:
  • It looks like you're trying to step through the code in ntdll.dll. That's a windows dll. Indeed its source code is not available. There is no point in trying to attach a debugger to ntdll. It's not going to help you.
  • You're getting an exception because ntdll is trying to load a dll but the dll cannot be found. Unfortunately, the error message you show does not tell us what dll cannot be found. I presume it's one of matlab dll.
Have you followed the instructions on this page and have you tested your build environment and checked that it work?
@Walter, yes .lib are statically linked. However, I've just tested an the exe still need the dll version of libMatlabEngine and libMatlabDataArray, presumably because the static libraries loads them.
When I read about what NTDLL is for, it really looked to me as if it should not be invoking any DLL, as NTDLL is responsible for some services when the NT kernel is not running, such as to be able to create defragmenters that run before the operating system is fully loaded.

Sign in to comment.

 Accepted Answer

It looks like the matlab engine requires access to matlab dlls under matlabroot\extern\bin\win64
As badly explained under the Runtime Environment section of the Build C++ engine programs help, you need to add that folder to the PATH variable. So under control panel->system->advanced system settings->environment variables, edit the PATH (of the user or system for all users) variable to add: C:\program files\matlab\R2017b\extern\bin\win64 (if that's where the above resolves to).

5 Comments

thank you. that's what exactly i was looking for.
Hello, I opened the win64 folder and there is no libMatlabEngine.dll file. Is this an installation error?
What release are you using? In particular, are you using release R2017b or later?
I suspect you're using a version < R2017b, in which case, the C++ engine is not available to you.
Hi, I am using 2018b. My mistake, I was looking in the "C:\matlab\R2018b\bin\win64" folder.

Sign in to comment.

More Answers (0)

Categories

Find more on Programming 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!