China Naming Network - Company naming - How to convert M file of Matlab into EXE file

How to convert M file of Matlab into EXE file

This problem has just been solved recently. If you follow the following steps, there will be no problem. I have run it successfully, but if your program encounters a bug, there will be an error. Close the whole program.

I hope these are useful to you.

How to compile MATLAB program into an independent executable program? How to publish a compiled independent executable program on a computer without MATLAB? The following objectives will be gradually achieved:

First, the step of generating an independent executable program (exe file)

1. Install the compiler. There are many choices. Matlab comes with an LCC, and VC++6.0 is recommended. I realized it based on VS 2003.

2. Set the compiler. Enter mbuild -setup and mex -setup at the command line of matlab, and select the installed C compiler.

3. Call the compiler. Here, a GUI platform based on MATLAB is fully implemented under deploytool. You can view it by typing deploytool in the command window. Please help with the specific usage.

Of course, you can also enter mcc -m filaname, where filaname is the m file to be converted into exe;

Note: In previous versions, use the compilation command MCC-B sgl CPP filaname;; ; Since the 2006 edition, it has been replaced by mcc -mfilaname; ;

Step 4 install

Second, run executable programs without matlab.

MCR is the running environment of matlab, which occupies less than 300 mm. For exe files generated by different matlab versions, MCR versions will be different. Therefore, when packaging the program, it is best to package the corresponding versions of MCR together. The setting file storage directory of MCR environment is as follows:

& ltmatlab path & gt \ toolbox \ compiler \ deploy \ win32.

The file name is MCRInstaller.exe. You can copy it to your own folder (before mglinstaller.exe 7.0).

The way to run an executable program in MATLAB is to add one in front! , such as: Picshow, suffix is optional.

Before running exe files on other machines without matlab installed:

First, install the running environment of matlab. Different versions of matlab environment can coexist on the same machine (in other words, different versions are incompatible).

Secondly, the path "MCRinstaller.exe installation directory \runtime\win32" is added to the environment variable of the computer, which is usually automatically loaded.

If not, you can also install it manually by adding the following:

Right-click My Computer, Properties, Advanced, Environment Variables and Add, specify a variable name, and then copy the above path into it.

Note: During the installation process, a pop-up window will pop up for Microsoft. NETFramework can not be installed.

Finally, copy the compiled files to the same directory, and double-click to run.

Problem: At present, this method can run on a computer without MATLAB and C/C++, but it can run on AMD's CPU, but there will be no interface for MATLAB compilation.

The fly in the ointment is that the black window of dos always exists at runtime. The method of eliminating the black screen is as follows:

The method of eliminating dos black screen when running exe program generated by MATLAB

After generating exe file based on MATLAB, there is a problem of dos black screen every time it runs. Now it can be solved by the following methods:

Method 1: Enter:

CD (preferred directory)

Edit compopts.bat

Add the following statement at the end of the open file:

A. in the VC environment:

set link flags = % link flags %/SUBSYSTEM:WINDOWS/ENTRY:mainCRTStartup

B. In the environment of B.LCC:

set link flags = % link flags %-subsystem windows

C.Borland:

set LINKFLAGS=%LINKFLAGS% -aa

After saving, recompile the M file, and the generated exe file will run without a dos window.

Method 2: Use inhibition tools:

After downloading the attached suppress package, unzip it. (Of course, you can also go to Google and download it again. ) You will see a suppress.ini file, open it in Notepad, and then change the name of test.exe in "Name=test.exe" to the name of the EXE file you generated. Put suppress.ini (with the icon to close the disk and display it) and the modified suppress.ini in the same directory as the exe you generated. Execute suppress.exe or self-generated exe. Of course, you can change suppress.exe's name by yourself and change it to the name you want.

Once the exe generated by one method is run on a computer without any MATLAB installed, there will be no black screen.

The disadvantage of the second method is that the exe you generated and the supress.exe must exist in the same directory.