! r. y% t8 g5 z) ]mcc , k# z% D% A8 e! S7 R, @- h+ { l1 x 9 y6 u4 I& Q: k- {+ N+ {& Kmatlab与VC++混编的两个重要的且强大的命令mbuild和mcc,前者我们相对用得较少,故主要一般先从后者mcc的使用入手,其实在上一节中我们已经领略到了它的威力。" R+ F. P5 s, D
实际上,关于mcc(matlab compiler command)乃至混合编程,最好的使用教程就是matlab的help和官方网站提供的user’s guide等文档。这里不妨截取其中的一部分来说明吧,个人觉得原文应该比中文讲解得更细致,当然这里只提供了一部分主干线索,引入门吧,具体深入修行靠个人了。8 x# z5 Y. L' D3 h0 Z/ c6 r
T4 _2 e/ S( v1 c( Q" A# a" K- i' ]
mcc 2 l! x+ x+ n* ^9 L, J S# {Invoke MATLAB Compiler / C6 v' H) c% w/ V0 v
Syntax mcc [-options] mfile1 [mfile2 ... mfileN]1 V4 b+ j2 I" P. m* a
[C/C++file1 ... C/C++fileN] % z1 `7 D0 n$ v9 s 4 m7 l) v7 @% _6 i) k1. Description- Z! i9 k8 x. o0 V
mcc is the MATLAB command that invokes the MATLAB Compiler. You can issue the mcc command either from the MATLAB command prompt (MATLAB mode) or the DOS or UNIX command line (stand-alone mode).) Y& ]/ D9 H" R; `( @/ S) _, |
8 q6 o$ T; p7 h9 t. P, J
; n2 R+ T) q: y8 g0 B9 U+ `7 }7 M
2. Command Line Syntax- L' `* O6 D9 x! `# M9 S% i
You may specify one or more MATLAB Compiler option flags to mcc. Most option flags have a one-letter name. You can list options separately on the command line, for example: i. v2 X. h' \& A, `
mcc -m -g myfun 8 V$ h/ `& W9 k* w& v3 J' l* d" O' U+ ]5 U& C: s; ^
You can group options that do not take arguments by preceding the list of option flags with a single dash (-), for example: 9 e$ K6 ^- T9 Z. L: W6 ]" R
mcc -mg myfun- b( C' R* r. o8 e+ u y3 d. d
- M( D9 E# X9 ~- B- }Options that take arguments cannot be combined unless you place the option with its arguments last in the list. For example, these formats are valid: - a! Z$ }0 Q! r. Y [6 J3 cmcc -m -A full myfun % Options listed separately$ R" J5 Z- f9 n: `! {# c
mcc -mA full myfun % Options combined, A option last) h% o& R( m" y: o. d/ m* }% l
This format is not valid: 4 q3 ^% m2 |# l1 {2 u' Z0 Tmcc -Am full myfun % Options combined, A option not last 4 o3 B% a1 M: M* _4 p/ _! p% A8 |7 i- V+ j4 A! e8 Z O
+ {+ B- T! I3 n- v6 a
3. Using Macros to Simplify Compilation 7 c0 j1 _7 A% [' I, u; o The MATLAB Compiler, through its exhaustive set of options, gives you access to the tools you need to do your job. If you want a simplified approach to compilation, you can use one simple option, i.e., macro, that allows you to quickly accomplish basic compilation tasks. If you want to take advantage of the power of the Compiler, you can do whatever you desire to do by choosing various Compiler options. 2 Q5 a I" M( B- ~ Table 7-2, Macro Options, shows the relationship between the macro approach to accomplish a standard compilation and the multioption alternative. ) m! @, _& w! L9 v % W8 e6 d; q9 K' v$ P; }4 W: w ( `$ Q: Q, K Z" [5 @+ a. K" Y7 SUnderstanding a Macro Option. The -m option tells the Compiler to produce a stand-alone C application. The -m macro is equivalent to the series of options -t -W main -L C -T link:exe -h libmmfile.mlib0 p8 l# T. c' i* q$ w1 S9 f
4 M( t, }2 O. s4 G" y- gTable 7-3, -m Macro, shows the options that compose the -m macro and the information that they provide to the Compiler. , }8 S& q/ g7 B/ z+ j 6 Y/ Q; K4 j0 e3 {* J6 h9 k + l) d6 p3 D5 u) b d$ F' P( w 4 C7 Y! u) a9 C! a4. Macro Options3 |3 ~* Y& y; E' N- s' V. ^
The macro options provide a simplified way to accomplish basic compilation tasks.. `9 ]; Y0 m3 u
-g (Debug). This option is a macro that is equivalent to 3 e: S7 z; s, b- S& G0 }. q-G -A debugline:on -O none/ p. ^. I% X C6 ~+ z$ h- x
or 0 d' l- K" s3 E3 d$ l" a9 u! Y8 j# m-B macro_option_g# ?9 B9 J0 P; J3 A* U# m$ h
' p- t& l4 w6 Q4 L' s. I w5 s
-m (Stand-Alone C)., w% v9 Z0 k8 r \5 w+ }' j
mcc -m mymfile " I0 e0 u/ | o5 }1 X8 hThe -m option is equivalent to the series of options4 N3 Y( j( |9 l7 N$ i# C# V( Z
-W main -L C -t -T link:exe -h libmmfile.mlib ! b5 D9 G% r' k" ^2 D0 f, A7 O& }' Yor 7 k, U: w3 b& v. x3 k3 a
-B macro_option_m + I- g' t. e( u+ p6 H/ ?: d' R # e7 w' f# G9 z! u* C* b" N: d-p (Stand-Alone C++). 7 N1 n' O _* A+ C4 i0 Ymcc -p mymfile , I; R- e, @, U' H0 C2 h5 K% b/ iThe -p option is equivalent to the series of options ( b% T4 F$ H" y9 K2 Z H6 n
-W main -L Cpp -t -T link:exe -h libmmfile.mlib, r: ~# a' R' N- b2 r
or 2 j7 n: j1 O; k3 K: o* X$ e-B macro_option_p/ |0 C0 d2 G0 m7 I7 z; f5 Q
5 b5 q( g9 }* h& n: T3 O
-S (Simulink S-Function). , R/ F6 k& f0 K P( W& S9 C1 @ mcc -S mymfile $ O$ A# v6 f h8 n- q$ B* A1 xThe -S option is equivalent to the series of options % B Q7 {, n, G0 J" c3 h+ p Q
-W simulink -L C -t -T link:mex libmatlbmx.mlib2 i! ~% ^% T; w( \
or ! U0 G6 T/ C& c3 q9 ^! r0 o7 H& t9 E( w-B macro_option_s3 e/ s' X1 g3 ^3 N+ u% q
8 F, _7 i f% g3 }* x4 j5 b+ R-x (MEX-Function)." |9 ]9 k5 i5 e) K8 V6 H8 ~, A& H" \# v
mcc -x mymfile , x$ s, x. x" r. |# V$ {2 q, R+ xThe -x option is equivalent to the series of options , g, B2 M @+ Y* e0 W
-W mex -L C -t -T link:mexlibrary libmatlbmx.mlib / _' \" K6 x% ]' l; j" _or $ y/ {, V+ l" l% D! c
-B macro_option_x " M# } v W( R3 _; Y3 ^% R0 E3 ^) X1 f0 N9 k; ?' a. h% w
: q. `5 @% w/ h! b; W1 [
* E8 o1 ^) P& U* u0 O7 w0 N5. Bundle Files & z2 ?: E. V" {& X2 ^3 i This table shows the available bundle files.. q* r; r% m) n2 D3 {7 C: i 7 X+ J/ R6 d! O1 M : b, t. r5 L) S6 X6 T3 J" L& L& n7 v+ P9 i0 C
6.Examples: S" U) _0 o: C/ ^% c2 f ^
Make a C translation and a MEX-file for myfun.m: # \) p4 t) @ a
mcc -x myfun9 R$ y. I5 K' e' x1 }
Make a C translation and a stand-alone executable for myfun.m: # y. a" n, ?. t" j6 Umcc -m myfun ; D, z4 ?( R8 x) k! t' E3 }Make a C++ translation and a stand-alone executable for myfun.m: 4 T, E1 S% h; `) x" P9 D. L- lmcc -p myfun ) x' f; K0 a; ~ }" x a4 SMake a C translation and a Simulink S-function for myfun.m (using dynamically sized inputs and outputs): 6 R5 p- c( Q8 ?, Emcc -S myfun & K' W9 f" Z) u# U/ [Make a C translation and a Simulink S-function for myfun.m (explicitly calling for one input and two outputs): } ^, d3 v& K) E% Nmcc -S -u 1 -y 2 myfun . s9 N: H8 |0 o' V+ i% Y3 F% ?1 g" _# N) a5 Z' w3 `
看完这些help,不难理解>>mcc -p -B sglcpp Test.m为什么产生四个文件test.hpp、test.cpp、test_mainhg.cpp、test.exe,以及这四个文件的作用功能了。