Problem for programming m files DLL file --- from mathworks

zhaozj2021-02-16  79

Hi, I Have Done a test for create .m file to .dll to use in msvc 6.0. I put here with step by step of procedure, and hope it could help. 1. You need to have the matlab C / C library and . MATLAB Compiler in your computer 2. Set up your project in MSVC for working with MATLAB C Library Follow the instruction at:. http://www.mathworks.com/support/solutions/data/27257.shtml 3. Create the. Dll file from matlab mathworks.com/support/solutions/data/27671.shtml 4. Add the .dll in the appropriate Directory and build your .exe file in msvc . jackphan /// // EXAMPLE STEP BY STEP FOR CREATING .dll FILES USING 1.I have created the file mySquare.m in folder myMatlab (code in step 9) 2.Create the command line to get lib file D:. / MyDocuments / MathLab / MatlabC / myMatlab> mcc -t -LC -W lib: mySquarelib -T link: lib mySquare.m libmmfile.mlib 3.It will create 9 files: mySquare.c mySquare.h mySquarelib.c mySquarelib.h mySquarelib.exports mySquarelib.dll Mysquarelib.ex p mySquarelib.lib mySquarelib.mlib 4.Add the file mySquarelib.h into project 5.Create a new folder MyAddingLib in C: / matlabR12 / extern / lib / win32 then copy file mySquarelib.lib into it 6.Add, C: / matlabR12 / extern / lib / win32 / MyAddingLib into Additional library path (click Project Setting in MSVC menu, click Link, Input (in Category) (note: separated by comma) 7.Add mySquarelib.lib into Object / library modules: (note : No Comma, Separated By a Space (Click Project Setting In MSVC

menu, click Link, Input (in Category) 8.Add the file mySquarelib.dll into project Debug folder (example: my project name is Work02) or if you want you could add the file mySquarelib.dll into C: / matlabR12 / extern / lib / win32 9.this is my m-file (mysquare.m) function y = mysquare (x) y = x * x; 10.This is a project file cpp // Test.cpp #include #include "test.h" main () {cout << "Hello, test for matlab c compiler << Endl; test obj; double xx = 1.2; double yy = obj.calculateMysquare (1.2); return 0;} Double Test :: CalculateMySquare (double x) {mxArray * x_ptr; mxArray * y_ptr; double * pVal; / * Create an mxArray to input into mlfMySquare * / x_ptr = mlfScalar (x); / * Call the initial function * / mySquarelibInitialize () ; / * Call the implementation function * / y_ptr = mlfMySquare (x_ptr); // NOTE: NEED TO CAPITAL WORD 'M' / * Call the library termination function * / mySquarelibTerminate (); / * The return value from mlfMySquare is an mxArray So Wemet Extract The Data From it * / pval = mxgetpr (y_ptr); double y = * pval; return y;} // test.h #include "matlab.hpp" #include "mysquarelib.h" class test {public: double CalculateMysquare (Double X ); Test () {;} ~ test () {;}}; // end class 11. summary: you need 2 Files from 9 Files Which Are Created from Matlab Ben Wrote:>>> To Convert You Matlab Code To C or C USE MCC, TYPE HELP MCC for> More Information,>> To Speed ​​Up Your Program, I Guess Thating Your Matlab Code The a> Lot of For Loops, Matlab Is Not Good with Loops>> Say for i = 1 : .001: 1000 '> Do any Calculation> End>>>>

转载请注明原文地址:https://www.9cbs.com/read-10872.html

New Post(0)