A lab project needs to call the MATLAB program. After repeated consideration, we decided to use VC to call the form of MATLAB export and warehouse delivery. I am mainly responsible for integrating with the MATLAB program. The following is a brief summary of today's work. It should be a memo.
1: Select compiler in MATLAB.
In the command line window, enter: Mex-Setup
Follow the prompts to select VC6.0. because you are using PhP7, vs2010 and 2008 are not recognized, but vc6.0 is installed. But I heard that the latest version of MATLAB can be identified.
2: Select builder.
Input: mbuilder-Setup
Select vc6.0
3: generate DLL.
Input: Mex-W cpplib: mydll-T link: Lib test. m
4: Use DLL in VC.
1: configure the environment
1: In the VC ++ directory
Include Directory: 1: directory where the generated mydll. H is located.
2: include directory in MATLAB.
Library Directory: 1: directory where mydll. Lib is located.
2: lib directory of Matlab.
: 2: Add dependency in connector-input-
Input: mydll. Lib mclmcrrt. Lib mclmcr. Lib
2: Add mydll. H to the project. Put mydll. dll and mydll. CTF in the project directory. // Isn't it just the. h and. DLL files? Why. CTF file. I don't understand.
Note:
1: Before calling the function in mydll in main, you must call the mydllinitilize () function. Otherwise, an error occurs.
For example
Int main () {If (! Mydllinitlize () {cout <"initialization failed! "<Endl; Return-1;} // call the function in the DLL. Return 0 ;}
2: After exporting the. M file to the dll library, if you need to compile the file again, you must first clear the directory where the original DLL is located. Otherwise, an error occurs in the Mexico function entry point missing. The specific cause is unknown. It is estimated that the new file fails to overwrite the original file. This is a blood lesson. It took me a lot of time to find errors.
3: When multiple DLL libraries exported by Matlab are called, lnk2005: void _ cdecl mclcppmlff multiply defined will appear during the connection.
That is, when void _ cdecl mclcppmlff is repeatedly defined. Take # ifndef... Method. I searched the internet and encountered a similar situation, but that guy did not solve it. Then I searched for the lnk2005 error. There are a lot of solutions. Finally, you can choose "Project Properties"> "Configure properties"> "linker"> "command line"> "/force" to force the system to ignore this error. At least this error is solved in any case.
Ithzhang
2012.4.7 pm
Supplement