Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Help: VS2005 Compile *.m file

all

I have test.m( matlab source code) file which implement A() function; and main.cpp file (will call A() ).

as you know ,we may do like the following steps:

  1. use matlab to compile test.m (mcc -) ,will generate : test.dll, test.ctf,test.h .

  2. copy the test.dll and test.ctf ,test.h file to VS2005 project. in main.cpp, call A() in test.dll.

But,when i release the programe,i will also pack the test.dll together.

And another way, can i using the VS2005 to compile both test.m and main.cpp which will only generate main.dll,main.ctf,main.h..( i will only release main.dll,main.ctf,main.h,).

this means, i compile the test.m into main.cpp.

And i have tried this way, in VS2005 ---> Build Events--> pre-Build Event-->command line: mcc C -w lib:test test.m

and it will generate the mid-file test.ctf(only test.ctf,no test.dll).But i don't know how to compile test.ctf into main.cpp ?

could anyone help me ?

thanks.

like image 563
Price Avatar asked Nov 14 '22 18:11

Price


1 Answers

You can do it the other way around and add your main.cpp to the matlab build process: I don't know the exact syntax, but you can add your main.cpp to mcc/mbuild, and it will add it to the dll for you. When using deploytool in gui mode, just drag c/c++ files to the resources area and they get compiled into the dll. So you'll have one dll only containing both m code and your own c++ code.

Another option, using the above strategy: first try the above, and look at the output of deploytool: it will show you the commands used. First it invokes mcc, then mbuild which in turn calls cl (the MS compiler). Use the exact command used to invoke mcc as a pre-build event, and then add that output files to cl in the same way mbuild does it (you can also see in the output how it does that). This way you can use VS to build a single dll anyway, just mimick what the matlab build process does.

Still I'm not sure how this is beneficial over distributing the two seperately. Also don't forget you have to distribute the entire MCR with it else your clients won't be able to run any code using the dll.

like image 141
stijn Avatar answered Dec 22 '22 09:12

stijn