The problem that Matlab 2017b cannot run after compiling to generate exe or DLL file and its solution

Problem Description

Recently tried mixed programming with Matlab 2017b and Qt 5.9. Write a very simple m file with Matlab, configure and use the Visual C++ 2015 compiler, use deploytool and compile the m file, and the exe file can be generated after compilation. There is no problem with all the environment variables, etc., but there will be problems when running the compiled program, and the DOS window will be closed after flashing.

Execute the compiled exe file in the DOS window, there is the following error message:

Fatal Internal Error:std::exception: Bundle#4 start failed: Loading D:\MATLAB2017b\bin\win64\matlab_startup_plugins\lmgrimpl\libmwlmgrimpl.dllfailed with error:    "

The problem should be that libmwlmgripl.dll failed to run. Online search found that this file is related to the license, but I am using the genuine Matlab 2017b, activated after connecting to the official website, it should not be a license problem.

I searched and checked a lot of information on the Internet, most of which describe the environment variable settings, compiler settings and other issues. I tried various settings and tossed for a day. Finally, I found the description and solution of this problem in Matlab Answers. Refer to the link below:

Compiled application doesnot run because of startup plugin libmwlmgrimpl.dll

https://cn.mathworks.com/matlabcentral/answers/373411-compiled-application-does-not-run-because-of-startup-plugin-libmwlmgrimpl-dll


This is a strange problem that only appeared in Matlab 2017b. It may be because the Matlab 2017b version is relatively new, and there are not many people who have encountered this problem, so there is no Chinese page to introduce this problem.

It is the official staff of MATLAB who answered this question, and it may be difficult for ordinary people to find out the reasons and solutions. In order to prevent students from falling into this pit and spending too much time, I translated and sorted out the information on this issue.


problem causes

This problem occurs because the versions of two DLL files in the system32 directory of Windows are too low, these two files are SSLEAY32.DLL and LIBEAY32.DLL.

These two files are also in the \bin\win64 directory of the MATLAB installation directory. The \bin\win64 directory is added to the system's PATH variable. However, when the exe program compiled by Matlab is running, the system32 directory has a high priority, and these two files in the system32 directory will be used, resulting in an initialization error and a direct flashback.

Solution

Knowing the cause, there are two workarounds:

(1) Copy SSLEAY32.DLL and LIBEAY32.DLL under the installation directory \bin\win64 of Matlab to the system32 directory of Windows, overwriting the files of the old version. But doing so may cause problems with other programs that use the two DLL files.

(2) Copy the SSLEAY32.DLL and LIBEAY32.DLL files in the installation directory \bin\win64 of Matlab to the same directory as the compiled exe, so that the exe file will find these two DLL files in its own directory when it is running. , instead of using the DLL files in the windows\system32 directory.


Test effect

In order to check the running effect of the program, a simple function to draw sin curve is written, with no input and output parameters.

function   drawsin()
% draw sin curve, no input and output parameters
t=0:0.1:15;
y=sin(t);
plot(t,y);
end

Set the Visual C++ 2015 compiler to use the following configuration in the Matlab command window

>> mbuild -setup C++
 MBUILD is configured to use 'Microsoft Visual C++ 2015' for C++ language compilation.
Open the Matlab Compiler through the deploytool in the Matlab command line, select to generate a Standalone Application, add the drawsin.m file, and package and compile.

After successful compilation, the drawsin\for_testing directory is the generated drawsin.exe file. Copy the SSLEAY32.DLL and LIBEAY32.DLL files in the Matlab installation directory\bin\win64 directory to this directory.

Double-click the drawsin.exe file to run normally, and the result is as shown below.

P.S.

Compiling with MATLAB2017b to generate DLL files, and writing the program to call the generated DLL files in Qt 5.9, this problem also occurs without any other errors. Therefore, it is also necessary to copy SSLEAY32.DLL and LIBEAY32.DLL to the exe file directory generated by Qt compilation.





Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325662410&siteId=291194637