Sender: on the Sand of the Sahara Desert, the letter area: matlab
Title: Simplified M files into C / C files, VC compilation
Sending station: BBS Harbin Institute of Technology (Sat Jul 31 22:29:48 2004)
In this "summary: m file transformation to C / C language file, VC compilation", how to convert a M file to c
/ CPP file and compile in VC. This approach has an annoying place, every time you need to generate MATLAB
The big pile C and H documents were taken into VC. For example, I read a picture first to swell, then corrode, and then carry out wavelet transform, and finally
display. Such a program generates approximately more than 150 files, which is not convenient to copy these files each time. I tried it
Another way to simplify these work. That is, do not generate the CPP file to hand over the VC to compile, but directly in M
A DLL is generated in Atlab to hand over the VC to link. This requires only copy three no matter how many files generated.
A file.
1. Built a M file, content is: (I deliberately demonstrate image display in this program, parameter delivery and return)
%%%%%%%%%%%%%%%%%%%%%%
Function result = fork_2 (PARA)
X = [1 para 3];
Y = [1 3 1];
Plot (x, y);
Result = para * 2;
%%%%%%%%%%%%%%%%%%%%%%
After saving, in the command window:
Enter: (format: mcc -t -wlibhg:
Libmwsglm.mlib file name)
Mcc -t -wlibhg: fork2 -t link: lib -h libmmfile.mlib libmwsglm.mlib fork_2
Then you will find fork2.dll, fork2.lib, fork2.h in your working directory.
2. Built a dialog-based MFC application in VC, named TestFork2, add one
Button, and add a button response function, the function content is described in the fifth step. Be formed
3 files are copied to the TestFork2 directory of VC project.
3. Select: Project ---> Settings, select Input in the drop-down menu, select Input in the VC ---> Settings, optional list.
Add the contents listed in Appendix A in the object / library module, pay attention to the space to pass them open and ignore
Add the content listed in Appendix B in the library; select the property table C / C option, drop down the menu selection general,
Add the contents of the appendix C in the pre-processing program definition, the original content should be retained, and pay attention to the comma
Separate them. Select the precompiled headers option for the drop-down menu, select "Automatic Us
Compensation header, add stdafx.h, determined.
4. Select: Tools ---> Select, Properties page Select "Directory" in include files:
C: / matlab6p5 / extern / incrude
C: / matlab6p5 / extern / include / cpp
Note that according to your MATLAB's installation location, modify the above address accordingly.
Add in Library Files:
C: / matlab6p5 / extern / lib / win32
C: / MATLAB6P5 / EXTERN / LIB / WIN32 / Microsoft / MSVC60 Note that according to your MATLAB installation location, the above address should be modified accordingly.
5. Add the following header file to the file where the button response function is located:
......
#include "fork2.h"
......
Function Response Code is:
MxArray * Para = MXcreatedouplascalar (2);
MxArray * Result;
Fork2initialize ();
Result = MLFFORK_2 (PARA);
CString Str;
Str.Format ("% f", mxgetscalar (result));
AfxMessageBox (STR);
6. Add one of the links ---> input options mentioned in the third step: fork2.lib
7. Compile, connection, execution, everything OK!
Appendix A: Link Library
Libmmfile.lib libmatlb.lib libmx.lib libmat.lib libmatpm.lib
SGL.LIB Libmwsglm.lib libmwservices.lib libut.lib
Appendix B: ignore the library
MSVCRT.LIB
Appendix C: Preprocessing Program Definition
MSVC, IBMPC, MSWind
Appendix D: Further Reference
MxArray's use reference MATLAB website cmath_ug2b.pdf
"Summary: m files into C / C language files, VC compilation" can be found on this version.