MATLAB APPLICATION DEPLOYMENT - WEB EXAMPLE GUIDE Guide de l'utilisateur

Naviguer en ligne ou télécharger Guide de l'utilisateur pour Logiciel MATLAB APPLICATION DEPLOYMENT - WEB EXAMPLE GUIDE. MATLAB APPLICATION DEPLOYMENT - WEB EXAMPLE GUIDE User`s guide Manuel d'utilisatio

  • Télécharger
  • Ajouter à mon manuel
  • Imprimer
  • Page
    / 274
  • Table des matières
  • DEPANNAGE
  • MARQUE LIVRES
  • Noté. / 5. Basé sur avis des utilisateurs

Résumé du contenu

Page 1 - MATLAB Compiler

MATLAB Compiler The Language of Technical ComputingComputationVisualizationProgrammingUser’s GuideVersion 3

Page 3

4 Stand-Alone Applications4-24Note The MATLAB add-in for Visual Studio does not currently work with Microsoft Visual C/C++, Version 7.0.The add-in fo

Page 4

Building Stand-Alone Applications on PCs4-25your MATLAB path. If you add directories to your MATLAB path and want them to be visible to the MATLAB add

Page 5 - Stand-Alone Applications

4 Stand-Alone Applications4-26• See the MATLABAddin.hlp file in the <matlab>\bin\win32 directory, or• Click on the Help icon in the MATLAB add-i

Page 6

Distributing Stand-Alone Applications4-27Distributing Stand-Alone ApplicationsTo make packaging an application easier, all the necessary MATLAB run-ti

Page 7 - Controlling Code Generation

4 Stand-Alone Applications4-28Note If customers already have the MATLAB math and graphics run-time libraries installed on their system, they do not n

Page 8

Distributing Stand-Alone Applications4-29The ordinal #### could not be located in the dynamic-link library dforrt.dll.To fix this problem, locate dfor

Page 9 - Error and Warning Messages

4 Stand-Alone Applications4-30Building Shared LibrariesYou can use mbuild to build C shared libraries on both UNIX and the PC. All of the mbuild optio

Page 10 - Contents

Building COM Objects4-31Building COM ObjectsNote To create COM components from the MATLAB Compiler, you must have the MATLAB COM Builder installed on

Page 11

4 Stand-Alone Applications4-32Building Excel Plug-InsNote To create Excel plug-ins from the MATLAB Compiler, you must have the MATLAB Excel Builder i

Page 12 - Preface

Troubleshooting4-33TroubleshootingTroubleshooting mbuildThis section identifies some of the more common problems that might occur when configuring mbu

Page 13 - Using this Guide

PrefaceThis chapter provides information about this documentation set. The sections are as follows.Related Products (p. x) MathWorks products related

Page 14

4 Stand-Alone Applications4-34mbuild Works from Shell but Not from MATLAB (UNIX). If the commandmbuild ex1.cworks from the UNIX command prompt but doe

Page 15 - Introducing the

Troubleshooting4-35Troubleshooting the CompilerTypically, problems that occur when building stand-alone C and C++ applications involve mbuild. However

Page 16 - Introduction

4 Stand-Alone Applications4-36Coding with M-Files OnlyOne way to create a stand-alone application is to write all the source code in one or more M-fil

Page 17

Coding with M-Files Only4-37The -m option flag causes the MATLAB Compiler to generate C source code suitable for stand-alone applications. For example

Page 18 - New Features

4 Stand-Alone Applications4-38Figure 4-2: Building Two M-Files into a Stand-Alone C Applicationmrank.mmcc -t mrank.mmrank.cC CompilerObject FileC Com

Page 19 - Optimizations

Coding with M-Files Only4-39For C++ code, add -L cpp to the previous commands and use a C++ compiler instead of a C compiler.

Page 20 - Additional Data Type Support

4 Stand-Alone Applications4-40Alternative Ways of Compiling M-FilesThe previous section showed how to compile main.m and mrank.m separately. This sect

Page 21 - Running Compiler from MATLAB

Alternative Ways of Compiling M-Files4-41mcc -m main_main.c main.c rank.c mrank.cThe resulting stand-alone application uses your customized version of

Page 22

4 Stand-Alone Applications4-42Mixing M-Files and C or C++The examples in this section illustrate how to mix M-files and C or C++ source code files:• T

Page 23 - Uses of the Compiler

Mixing M-Files and C or C++4-43The Build ProcessThe steps needed to build this stand-alone application are1 Compile the M-code.2 Generate the library

Page 24 - (libmatlbmx)

PrefacexRelated ProductsThe MATLAB Compiler automatically converts MATLAB M-files to C and C++ code. The MATLAB Compiler includes the MATLAB C/C++ Ma

Page 25 - C++ Stand-Alone Applications

4 Stand-Alone Applications4-44Figure 4-3: Mixing M-Files and C Code to Form a Stand-Alone Applicationmrank.mmcc -t -W lib:Pkg -T link:exe mrank mrank

Page 26

Mixing M-Files and C or C++4-45mrankp.cThe code in mrankp.c calls mrank and outputs the values that mrank returns:/* * MRANKP.C * "Posix" C

Page 27

4 Stand-Alone Applications4-46 /* Print the results. */ mlfPrintMatrix(R); /* Free the matrices allocated during this computation. */

Page 28 - The MATLAB Compiler Family

Mixing M-Files and C or C++4-47mlfPrintMatrix is one of the many routines in the MATLAB Math Built-In Library, which is part of the MATLAB Math Librar

Page 29

4 Stand-Alone Applications4-48 mxArray *a, *b, *x, *y; double x_pr[ROWS * COLS] = {1, 2, 3, 4, 5, 6, 7, 8, 9}; double x_pi[ROWS * COLS] =

Page 30 - Why Compile M-Files?

Mixing M-Files and C or C++4-49You can build this program into a stand-alone application by using the commandmcc -t -W lib:multpkg -T link:exe multarg

Page 31 - Changed Data Type Names

4 Stand-Alone Applications4-50The mlfMultarg function returns matrices a and b. a has both real and imaginary components; b is a scalar having only a

Page 32 - Limitations and Restrictions

5ControllingCode GenerationThis chapter describes the code generated by the MATLAB Compiler and the options that you can use to control code generati

Page 33 - functionscalled

5 Controlling Code Generation5-2Code Generation OverviewExample M-FilesTo generate the various files created by the Compiler, this chapter uses severa

Page 34 - Workaround

Code Generation Overview5-3b = y;endfun M-Filefunction a = fun(b)a(1) = b(1) .* b(1);a(2) = b(1) + b(2);a(3) = b(2) / 4;sample M-Filefunction y = samp

Page 35

Using this GuidexiUsing this GuideThis book describes the MATLAB Compiler and provides numerous examples of how to use it. The topics included are• In

Page 36

5 Controlling Code Generation5-4 Note Many of the code snippets generated by the MATLAB Compiler that are used in this chapter use the -F page-width

Page 37 - Configuration

Compiling Private and Method Functions5-5Compiling Private and Method FunctionsPrivate functions are functions that reside in subdirectories with the

Page 38

5 Controlling Code Generation5-6This table lists the functions you can specify on the command line and their corresponding function and filenames.For

Page 39

Compiling Private and Method Functions5-7Since it is ambiguous which foo.m you are requesting, it generates the warningWarning: The specified private

Page 40 - UNIX Workstation

5 Controlling Code Generation5-8The Generated Header FilesThis section highlights the two header files that the Compiler can generate for the Sierpins

Page 41 - Compiler Options Files

The Generated Header Files5-9extern mxArray * mlfGasket(mxArray * numPoints);extern void mlxGasket(int nlhs, mxArray * plhs[],

Page 42 - Locating Options Files

5 Controlling Code Generation5-10extern mwArray gasket(mwArray numPoints = mwArray::DIN);#ifdef __cplusplusextern "C"#endifvoid mlxGasket(in

Page 43 - Choosing a Compiler

Internal Interface Functions5-11Internal Interface FunctionsThis section uses the Sierpinski Gasket example (gasket.m) to show several of the generate

Page 44 - Changing Compilers

5 Controlling Code Generation5-12 */void mlxGasket(int nlhs, mxArray * plhs[], int nrhs, mxArray * prhs[]) {

Page 45 - Creating MEX-Files

Internal Interface Functions5-13/* ------------- Output Argument Processing ----------- */ mlfRestorePreviousContext(0, 1, mprhs[0]); plhs[0] =

Page 46

PrefacexiiTypographical ConventionsThis manual uses some or all of these conventions.Item Convention ExampleExample code Monospace font To assign the

Page 47 - Verifying from MATLAB

5 Controlling Code Generation5-14This is the corresponding mlfNF interface function (mlfNFoo) for the foo.m example described earlier in this chapter.

Page 48

Internal Interface Functions5-15mlfVF Interface FunctionThe Compiler produces this interface function only when the M-function uses the variable nargo

Page 49 - Microsoft Windows on PCs

5 Controlling Code Generation5-16C++ Interface FunctionsThe C++ interface functions process any input arguments and pass them to the implementation ve

Page 50

Internal Interface Functions5-17 int i;mclCppUndefineArrays(1, mplhs); if (nlhs > 1) { error( mwVarargin(

Page 51

5 Controlling Code Generation5-18//// The function "gasket" contains the normal interface for// the "gasket" M-function from file/

Page 52

Internal Interface Functions5-19// function, appearing above.//mwArray Nfoo(int nargout, mwArray * b, mwArray x, m

Page 53

5 Controlling Code Generation5-20VF Interface FunctionThe Compiler produces this interface function only when the M-function uses the variable nargout

Page 54

Supported Executable Types5-21Supported Executable TypesWrapper functions create a link between the Compiler-generated code and a supported executable

Page 55

5 Controlling Code Generation5-22MEX-FilesThe -W mex -L C options produce the MEX-file wrapper, which includes the mexFunction interface that is stand

Page 56

Supported Executable Types5-23The Compiler processes the string arguments passed to the main() function and sends them into the compiled M-function as

Page 57

1Introducing theMATLAB CompilerThis chapter describes the MATLAB Compiler and its uses. It also includes new features, upgrading information, and lim

Page 58

5 Controlling Code Generation5-24Simulink S-FunctionsThe -W simulink -L C options produce a Simulink S-function wrapper. Simulink S-function wrappers

Page 59

Supported Executable Types5-25This example uses several functions from the toolbox\matlab\timefun directory (weekday, date, tic, calendar, toc) to cre

Page 60

5 Controlling Code Generation5-26-B csharedlib:libtimefunwith-t -W lib:libtimefun -T link:lib -h libmmfile.mlibgiving the new statementmcc -t -W lib:l

Page 61

Supported Executable Types5-27libtimefun.clibtimefun.hlibtimefun.exportslibtimefun.mliblibtimefun.extThe last file, libtimefun.ext, is the shared libr

Page 62

5 Controlling Code Generation5-28Note On the mcc command line, you can access any mlib file by including the full path to the file. For example:mcc -

Page 63

Supported Executable Types5-29This example uses several functions from the toolbox\matlab\timefun directory (weekday, date, tic, calendar, toc) to cre

Page 64

5 Controlling Code Generation5-30The COM wrapper options create a superset of the files created when producing a C or C++ library wrapper. In addition

Page 65

Supported Executable Types5-31When calling mbuild to link a library, the .dll file will be <component_name>_<major>_<minor>.dll. Thi

Page 66 - How the Function Works

5 Controlling Code Generation5-32How mbuild Processes the File TypesThe mbuild option, -regsvr, uses the mwregsvr32 program to register the resulting

Page 67

Supported Executable Types5-33C Signature.void mlxF(int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs[]);mxArray *mlfNF( int nargout, mxArr

Page 68 - 3 Working with MEX-Files

1 Introducing the MATLAB Compiler1-2IntroductionThis book describes Version 3.0 of the MATLAB® Compiler. The MATLAB Compiler takes M-files as input an

Page 69

5 Controlling Code Generation5-34Porting Generated Code to a Different PlatformThe code generated by the MATLAB Compiler is portable among platforms.

Page 70

Formatting Compiler-Generated Code5-35Formatting Compiler-Generated CodeThe formatting options allow you to control the look of the Compiler-generated

Page 71 - Using the -S Option

5 Controlling Code Generation5-36Default WidthNot specifying a page width formatting option uses the default of 80. Usingmcc -xg gasketgenerates this

Page 72 - Sample Time

Formatting Compiler-Generated Code5-37 NULL)); /* * * corners = [866 1;1 500;866 1000]; */ mclMline(15); mlfAssign(

Page 73 - Data Type

5 Controlling Code Generation5-38Default IndentationNot specifying indent formatting options uses the default of four spaces for statements and two sp

Page 74

Formatting Compiler-Generated Code5-39Modified IndentationThis example shows the same segment of code using a statement indentation of two and an expr

Page 75

5 Controlling Code Generation5-40Including M-File Information in Compiler OutputThe annotation options allow you to control the type of annotation in

Page 76

Including M-File Information in Compiler Output5-41Comments AnnotationTo include only comments from the source M-file in the generated output, usemcc

Page 77 - Applications

5 Controlling Code Generation5-42 mxDestroyArray(ans); mclSetCurrentLocalFunctionTable(save_local_function_table_); mclMlineExitFunction();}N

Page 78 - MEX-Files

Including M-File Information in Compiler Output5-43Note When using the #line directive, the page-width directive is disabled in order to make the cod

Page 79 - Stand-Alone C++ Applications

Introduction1-3Note The phrase MATLAB interpreter refers to the application that accepts MATLAB commands, executes M-files and MEX-files, and behaves

Page 80

5 Controlling Code Generation5-44Controlling Information in Run-Time ErrorsUse the debugline:setting option to include source filenames and line numbe

Page 81

Including M-File Information in Compiler Output5-45your results are??? Error using ==> tmmultError using ==> *Inner matrix dimensions must agree

Page 82 - Introducing mbuild

5 Controlling Code Generation5-46Interfacing M-Code to C/C++ CodeThe MATLAB Compiler supports calling arbitrary C/C++ functions from your M-code. You

Page 83 - Configuring for C or C++

Interfacing M-Code to C/C++ Code5-47private, or method). When using this pragma, the Compiler will generate an additional header file called file_exte

Page 84 - Using the System Compiler

5 Controlling Code Generation5-48We recommend that you include this header file when defining the function. This function could be implemented in this

Page 85

Interfacing M-Code to C/C++ Code5-49callback that references the specified function. Without this pragma, the -h option will not be able to locate and

Page 86

5 Controlling Code Generation5-50

Page 87 - Locating Shared Libraries

6Optimizing PerformanceThe MATLAB Compiler can perform various optimizations on your M-file source code that can make the performance of the generate

Page 88 - Running Your Application

6 Optimizing Performance6-2Optimization BundlesAll optimizations are controlled separately, and you can enable or disable any of the optimizations. To

Page 89 - Distribution Caveats

Optimization Bundles6-3• optimize_integer_for_loops• percolate_simple_types• speculateList All OptimizationsTo list all available optimizations, use-O

Page 90

1 Introducing the MATLAB Compiler1-4New FeaturesMATLAB Compiler 3.0• The MATLAB Compiler now includes the MATLAB C/C++ Math and Graphics Libraries.Not

Page 91

6 Optimizing Performance6-4Optimizing ArraysScalar Arrays(fold_scalar_mxarrays) When this optimization is enabled, all constant, scalar-valued array o

Page 92 - Compiler Restrictions

Optimizing Arrays6-5If you compile this with the -O none option, you get...mlfAssign(&y,mclMtimes(mlfDoubleMatrix(2, 2, _array0_, (double *)NULL),

Page 93

6 Optimizing Performance6-6Optimizing LoopsSimple Indexing(array_indexing) This optimization improves the performance of simple one- and two-dimension

Page 94

Optimizing Loops6-7Note This optimization causes the variable names in the resulting C program to differ from those in the M-file. Therefore, we reco

Page 95

6 Optimizing Performance6-8for (; ; ) {...if (v_ == e_) {break;}++v_;}mlfAssign(&i, mlfScalar(v_));}...

Page 96

Optimizing Conditionals6-9Optimizing Conditionals(optimize_conditionals) This optimization reduces the MATLAB conditional operators to scalar C condit

Page 97

6 Optimizing Performance6-10Optimizing MATLAB ArraysScalars(percolate_simple_types) This optimization reduces the strength of operations on simple typ

Page 99 - About the mbuild Script

7 Reference7-2Functions — By CategoryPragmasCompiler FunctionsCommand Line Tools%#externalCall arbitrary C/C++ functions.%#functionfeval pragma.%#mexP

Page 100 - 4 Stand-Alone Applications

7-3Code Generation OptionsControl Compiler output.Optimization Options Improve the performance of the generated C/C++ code.Compiler and Environment Op

Page 101

New Features1-5• The new option, -b, causes the Compiler to generate a Visual Basic (.bas) file that contains the Microsoft Excel Formula Function int

Page 102

7 7-4Functions — By Name 7%#external . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-5%#fun

Page 103 - Installing Your Application

%#external7-57%#externalPurpose Pragma to call arbitrary C/C++ functions from your M-codeSyntax %#externalDescription The %#external pragma informs th

Page 104 - On UNIX Systems

%#function7-67%#functionPurpose feval pragmaSyntax %#function <function_name-list>Description This pragma informs the MATLAB Compiler that the s

Page 105

%#mex7-77%#mexPurpose mex pragmaSyntax %#mexDescription This pragma informs the MATLAB Compiler to select the MEX-file over an existing M-file.If you

Page 106

mbchar7-87mbcharPurpose Assert variable is a MATLAB character stringSyntax mbchar(x)Description The statementmbchar(x)causes the MATLAB Compiler to im

Page 107 - Building COM Objects

mbcharscalar7-97mbcharscalarPurpose Assert variable is a character scalarSyntax mbcharscalar(x)Description The statementmbcharscalar(x)causes the MATL

Page 108

mbcharvector7-107mbcharvectorPurpose Assert variable is a character vector, i.e., a MATLAB stringSyntax mbcharvector(x)Description The statementmbchar

Page 109 - Troubleshooting

mbint7-117mbintPurpose Assert variable is integerSyntax mbint(n)Description The statementmbint(x)causes the MATLAB Compiler to impute that x is an int

Page 110

mbint7-12x = 4 + 7.5i;Example This code in MATLAB causes mbint to generate an error message because n does not hold an integer value:n = 17.4;mbint(n)

Page 111 - Troubleshooting the Compiler

mbintscalar7-137mbintscalarPurpose Assert variable is integer scalarSyntax mbintscalar(n)Description The statementmbintscalar(x)causes the MATLAB Comp

Page 112

How to Contact The MathWorks:www.mathworks.com Webcomp.soft-sys.matlab [email protected] Technical [email protected] Product e

Page 113 - Coding with M-Files Only

1 Introducing the MATLAB Compiler1-6Conditional Expressions. Reduces the MATLAB conditional operators to scalar C conditional operators when both oper

Page 114

mbintvector7-147mbintvectorPurpose Assert variable is integer vectorSyntax mbintvector(n)Description The statementmbintvector(x)causes the MATLAB Comp

Page 115

mbreal7-157mbrealPurpose Assert variable is realSyntax mbreal(n)Description The statementmbreal(x)causes the MATLAB Compiler to impute that x is real

Page 116

mbrealscalar7-167mbrealscalarPurpose Assert variable is real scalarSyntax mbrealscalar(n)Description The statementmbrealscalar(x)causes the MATLAB Com

Page 117 - Functions

mbrealvector7-177mbrealvectorPurpose Assert variable is a real vectorSyntax mbrealvector(n)Description The statementmbrealvector(x)causes the MATLAB C

Page 118

mbscalar7-187mbscalarPurpose Assert variable is scalarSyntax mbscalar(n)Description The statementmbscalar(x)causes the MATLAB Compiler to impute that

Page 119 - The Build Process

mbvector7-197mbvectorPurpose Assert variable is vectorSyntax mbvector(n)Description The statementmbvector(x)causes the MATLAB Compiler to impute that

Page 120

mbuild7-207mbuildPurpose Compile and link source files that call functions in the MATLAB C/C++ Math Library or MATLAB C/C++ Graphics Library into a st

Page 121 - Mixing M-Files and C or C++

mbuild7-21-D<name>#<value>Define a symbol name and value to the C/C++ preprocessor. Equivalent to a #define <name> <value> di

Page 122 - An Explanation of mrankp.c

mbuild7-22-lang <language>Specify compiler language. <language> can be c or cpp. By default, mbuild determines which compiler (C or C++) t

Page 123 - Advanced C Example

mbuild7-23-regsvr(Windows) Use the regsvr32 program to register the resulting shared library at the end of compilation. The Compiler uses this option

Page 124

New Features1-7Faster C/C++ Math Library ApplicationsThe improved performance of the C/C++ Math Library is due in part to the added scalar accelerated

Page 125 - An Explanation of This C Code

mbuild7-24Note Some of these options (-f, -g, and -v) are available on the mcc command line and are passed along to mbuild. Others can be passed alon

Page 126

mcc7-257mccPurpose Invoke MATLAB CompilerSyntax mcc [-options] mfile1 [mfile2 ... mfileN][C/C++file1 ... C/C++fileN]Description mcc is the MATLAB comm

Page 127 - Code Generation

mcc7-26compilation, you can use one simple option, i.e., macro, that allows you to quickly accomplish basic compilation tasks. If you want to take adv

Page 128 - Sierpinski Gasket M-File

mcc7-27Table 7-3, -m Macro, shows the options that compose the -m macro and the information that they provide to the Compiler.Changing Macro Options.

Page 129 - Generated Code

mcc7-28command line options. Both the mccstartup file and the -B option are processed the same way.Note If you need to change the meaning of a macro

Page 130 - 5 Controlling Code Generation

mcc7-29Conflicting Options on Command LineIf you use conflicting options, the Compiler resolves them from left to right, with the rightmost option tak

Page 131

mcc7-30mcc -m -I /home/user/dir1 -I /home/user/dir2 myfile.mThe Compiler finds the myfile.m in dir1 and compiles it instead of the one in dir2 because

Page 132

mcc7-31MATLAB Compiler Option FlagsThe MATLAB Compiler option flags perform various functions that affect the generated code and how the Compiler beha

Page 133

mcc7-32In addition to the -G option, the -g option includes the -A debugline:on option. This will have an impact on performance of the generated code.

Page 134

mcc7-33-S (Simulink S-Function). Produce a Simulink S-function that is compatible with the Simulink S-Function block. For example, to translate an M-f

Page 135 - C++ Header File

1 Introducing the MATLAB Compiler1-8Running Compiler from DOS/UNIX ShellIf you run the Compiler from a DOS or UNIX shell, you are running from “outsid

Page 136

mcc7-34-B sgl -t -W comhg:<component_name>,<class_name>,<version> -T link:lib -h libmmfile.mlib -i-B csglexcel (C Handle Graphics Ex

Page 137 - Internal Interface Functions

mcc7-35-B csharedlib (C Shared Library). Produce a C shared library. The -B csharedlib option is equivalent to the series of options-t -W lib:<shar

Page 138

mcc7-36Table 7-5, Code/Comment Annotation Options, shows the available annotation options.To control the #line preprocessor directives that are includ

Page 139

mcc7-37Table 7-7, Run-Time Error Annotation Options, shows the available debugline directive settings.For example, to include all of your M-code, incl

Page 140

mcc7-38-l (Line Numbers) . Generate C/C++ code that prints filename and line numbers on run-time errors. This option flag is useful for debugging, but

Page 141

mcc7-39-u (Number of Inputs). Provide more control over the number of valid inputs for your Simulink S-function. This option specifically sets the num

Page 142

mcc7-40Caution When generating function wrappers, you must specify all M-files that are being linked together on the command line. These files are us

Page 143 - F Interface Function

mcc7-41-y (Number of Outputs). Provide more control over the number of valid outputs for your Simulink S-function. This option specifically sets the n

Page 144 - NF Interface Function

mcc7-42Note You can use the -B option with a replacement expression as is at the DOS or UNIX prompt. To use -B with a replacement expression at the M

Page 145

mcc7-43-c (C Code Only). When used with a macro option, generate C code but do not invoke mex or mbuild, i.e., do not produce a MEX-file or stand-alon

Page 146 - VF Interface Function

Uses of the Compiler1-9Uses of the CompilerThe MATLAB Compiler (mcc) can translate M-files into C files. The resultant C files can be used in any of t

Page 147 - Supported Executable Types

mcc7-44The -h option purposely does not include built-in functions or functions that appear in the MATLAB M-File Math Library portion of the C/C++ Mat

Page 148 - POSIX Main Wrapper

mcc7-45Table 7-11: Output Stage Options <Target> DescriptioncodegenTranslates M-files to C/C++ files and generates a wrapper file. The default

Page 149

mcc7-46-v (Verbose). Display the steps in compilation, including• The Compiler version number• The source filenames as they are processed• The names o

Page 150

mcc7-47-Y <license.dat File>. Use license information in license.dat file when checking out a Compiler license.mbuild/mex Options-f <filename

Page 151 - C Shared Library

mcc7-48Note Multiple -M options do not accumulate; only the last -M option is used.-z <path> (Specifying Library Paths). Specify the path to us

Page 152

mcc7-49mcc -t -L C myfunMake a generic C++ translation of myfun.m:mcc -t -L Cpp myfunMake a C MEX wrapper file from myfun1.m and myfun2.m:mcc -W mex -

Page 153

mcc7-50

Page 154

AMATLAB CompilerQuick ReferenceThis appendix summarizes the Compiler options and provides brief descriptions of how to perform common tasks.Common Us

Page 155 - COM Components

A MATLAB Compiler Quick ReferenceA-2Common Uses of the CompilerThis section summarizes how to use the MATLAB Compiler to generate some of its more sta

Page 156

Common Uses of the CompilerA-3Create a C++ Library. To create a C++ library, usemcc -p -W lib:libfoo -T compile:lib foo.mCreate a C Shared Library.To

Page 157

1 Introducing the MATLAB Compiler1-10Figure 1-1: Developing MEX-FilesMATLAB users who do not have the MATLAB Compiler must write the source code for

Page 158 - COM Signature

A MATLAB Compiler Quick ReferenceA-4mccBold entries in the Comment/Options column indicate default values.Table A-1: mcc Quick Reference Option Descr

Page 159

mccA-5F optionSpecifies format parametersoption = listexpression-indent:npage-width:nstatement-indent:ngGenerates debugging informationEquivalent to-

Page 160

A MATLAB Compiler Quick ReferenceA-6O option:[on|off]O allO noneO listBuild an optimized executable.option =array_indexingfold_mxarraysfold_non_scalar

Page 161 - Setting Page Width

mccA-7w optionDisplays warning messagesoption = listlevellevel:stringwhere level = disableenableerrorNo w option displays only serious warnings (defa

Page 162

A MATLAB Compiler Quick ReferenceA-8

Page 163 - Setting Indentation Spacing

BError and Warning MessagesThis appendix lists and describes error messages and warnings generated by the MATLAB Compiler. Compile-time messages are

Page 164

B Error and Warning MessagesB-2Compile-Time ErrorsError: An error occurred while shelling out to mex/mbuild (error code = errorno). Unable to build ex

Page 165 - Modified Indentation

Compile-Time ErrorsB-3Error: File: filename Line: # Column: # () indexing must appear last in an index expression.If you use ordinary array indexing (

Page 166

B Error and Warning MessagesB-4Error: File: filename Line: # Column: # An array for multiple LHS assignment cannot contain token.If the left-hand side

Page 167 - All Annotation

Compile-Time ErrorsB-5Error: File: filename Line: # Column: # Missing variable or function. An illegal name was used for a variable or function. For e

Page 168 - No Annotation

Uses of the Compiler1-11Creating Stand-Alone ApplicationsC Stand-Alone ApplicationsThe MATLAB Compiler, when invoked with the -m macro option, transla

Page 169 - Include #line Directives

B Error and Warning MessagesB-6Error: File: filename Line: # Column: # The PERSISTENT declaration must precede any use of the variable variablename.In

Page 170

Compile-Time ErrorsB-7Error: Found illegal whitespace character in command line option: "string". The strings on the left and right side of

Page 171

B Error and Warning MessagesB-8Error: The argument after the -option option must contain a colon. The format for this argument requires a colon. For m

Page 172

Compile-Time ErrorsB-9Error: The specified file "filename" cannot be read. There is a problem with your specified file. For example, the fil

Page 173

B Error and Warning MessagesB-10Error: Unknown annotation option: optionname. An invalid string was specified after the -A option. For a complete list

Page 174 - Using feval

Warning MessagesB-11Warning MessagesThis section lists the warning messages that the MATLAB Compiler can generate. Using the -w option for mcc, you ca

Page 175 - Compiling MEX-Files

B Error and Warning MessagesB-12Warning: File: filename Line: # Column: # The call to function "functionname" on this line could not be boun

Page 176

Warning MessagesB-13will be called through an feval call. This is used so that the -h option will automatically compile the selected functions.Warning

Page 177 - Optimizing Performance

B Error and Warning MessagesB-14Warning: File: filename Line: # Column: # The load statement cannot be translated unless it specifically lists the nam

Page 178 - Turn Off All Optimizations

Warning MessagesB-15Warning: File: filename Line: # Column: # The second output argument from the "functionname" function is only available

Page 179 - List All Optimizations

1 Introducing the MATLAB Compiler1-12Figure 1-2: Developing a Typical Stand-Alone C ApplicationM-File function to find the rank of a magic squaremcc

Page 180 - 6 Optimizing Performance

B Error and Warning MessagesB-16Warning: M-file "filename" was specified on the command line with full path of "pathname", but was

Page 181 - Optimizing Arrays

Warning MessagesB-17Warning: The name of a shared library should begin with the letters "lib". "libraryname" doesn’t.(missing_lib_

Page 182

B Error and Warning MessagesB-18Run-Time ErrorsNote The error messages described in this section are generated by the Compiler into the code exactly

Page 183 - Optimizing Loops

Run-Time ErrorsB-19Run-time Error: File: filename Line: # Column: # The function "functionname" was called with more than the declared numbe

Page 184

B Error and Warning MessagesB-20

Page 185 - Optimizing Conditionals

I-1IndexSymbols#line directives 5-42%#external 7-5%#function 7-6%#mex 7-7%#mex pragma 7-7.cshrc 4-11.DEF file 4-22A-A option flag 7-35add-inMATLAB for

Page 186

IndexI-2C++compilerssupported on PCs 2-14supported on UNIX 2-4interfacing to M-code 5-46library wrapper 5-28required featurestemplates 4-6callback pro

Page 187 - Reference

IndexI-3dualitycommand/function 5-22Eembedded M-file 7-30environment variable 2-26library path 4-11out of environment space on Windows 2-25error messa

Page 188 - 7 Reference

IndexI-4G-G option flag 7-47-g option flag 7-31gasket.m 3-2gcc compiler 2-4generated Compiler files 5-3generating P-code 7-35graphics applicationstrou

Page 189

IndexI-5limitations of MATLAB Compiler 2.0 1-18built-in functions 1-18exist 1-18objects 1-18script M-file 1-18#line directives 5-42line numbers 7-38Li

Page 190 - Functions — By Name 7

Uses of the Compiler1-13See Chapter 4, “Stand-Alone Applications” for complete details regarding stand-alone applications.Figure 1-2, Developing a Typ

Page 191 - Syntax %#external

IndexI-6MATLAB librariesM-file Math 4-40, 7-44MATLAB plug-ins. See MEX wrapper.Matrix data type 1-17mbchar 7-8mbcharscalar 7-9mbcharvector 7-10mbint 7

Page 192 - Purpose feval pragma

IndexI-7M-filecompiling embedded 7-30examplegasket.m 3-2houdini.m 3-10main.m 4-36mrank.m 4-36, 4-42function 3-10MATLAB-provided 4-40script 1-18, 3-10M

Page 193 - Syntax %#mex

IndexI-8options filecombining customized on PC 4-21locating 2-16locating on PC 4-16locating on UNIX 4-8making changes persist onPC 4-20UNIX 4-10modify

Page 194 - Description The statement

IndexI-9scalar arraysfolding 6-4script M-file 1-18, 3-10converting to function M-files 3-10setting default options 7-27S-function 3-7generating 3-7pas

Page 195 - Syntax mbcharscalar(x)

IndexI-10templates requirement 4-6translate M to C-t option flag 7-44troubleshootingCompiler problems 2-27, 4-35mbuild problems 4-33MEX-file problems

Page 196 - Syntax mbcharvector(x)

1 Introducing the MATLAB Compiler1-14The MATLAB Compiler FamilyThis figure illustrates the various ways you can use the MATLAB Compiler. The shaded bl

Page 197 - Syntax mbint(n)

The MATLAB Compiler Family1-15The Compiler takes your M-file(s) and can generate C or C++ code. It can also generate a wrapper file depending on your

Page 198 - , mbintvector, mcc

iContentsPrefaceRelated Products . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xUsing this Guide . . . . . . . . .

Page 199 - See Also mbint, mbscalar, mcc

1 Introducing the MATLAB Compiler1-16Why Compile M-Files?There are several reasons to compile M-files:• To create stand-alone applications• To create

Page 200 - Syntax mbintvector(n)

Upgrading from Previous Versions of the Compiler1-17Upgrading from Previous Versions of the CompilerMATLAB Compiler 3.0 is fully compatible with previ

Page 201 - Syntax mbreal(n)

1 Introducing the MATLAB Compiler1-18Limitations and RestrictionsMATLAB CodeMATLAB Compiler 3.0 supports almost all of the functionality of MATLAB. Ho

Page 202 - Syntax mbrealscalar(n)

Limitations and Restrictions1-19if (y==3)persistent xelsex = 3;endStand-Alone ApplicationsThe restrictions and limitations noted in the previous secti

Page 203 - Syntax mbrealvector(n)

1 Introducing the MATLAB Compiler1-20Fixing Callback Problems: Missing Functions When the Compiler creates a stand-alone application, it compiles the

Page 204 - Syntax mbscalar(n)

Limitations and Restrictions1-21in callback strings.) The Compiler processes any function listed in a %#function pragma.For example, the call to the c

Page 205 - Syntax mbvector(n)

1 Introducing the MATLAB Compiler1-22

Page 206

2Installation and ConfigurationThis chapter describes the system requirements for the MATLAB Compiler and installation and configuration information.

Page 207

2 Installation and Configuration2-2System Configuration for MEX-FilesThis section outlines the steps necessary to configure your system to create MEX-

Page 208

System Configuration for MEX-Files2-3Figure 2-1: MATLAB Compiler Installation Sequence for Creating MEX-FilesStartIs ANSI C or C++compiler installedF

Page 209

ii ContentsCOM Components . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-16Hiding Proprietary Algorithms . . . . . . . .

Page 210

2 Installation and Configuration2-4UNIX WorkstationThis section examines the system requirements, installation procedures, and configuration procedure

Page 211 - Command Line Syntax

UNIX Workstation2-5Note For a list of all the compilers supported by MATLAB, see the MathWorks Technical Support Department’s Technical Notes athttp:

Page 212

2 Installation and Configuration2-6shows the preconfigured options files that are included with MATLAB for UNIX.Information on the options files is pr

Page 213 - Setting Up Default Options

UNIX Workstation2-7ANSI C or C++ CompilerTo install your ANSI C or C++ compiler, follow the vendor’s instructions that accompany your C or C++ compile

Page 214

2 Installation and Configuration2-8If you do not need to change C or C++ compilers, or you do not need to modify your compiler options files, you can

Page 215 - Handling Full Pathnames

UNIX Workstation2-9Note The setup option creates a user-specific, matlab directory in your individual home directory and copies the appropriate optio

Page 216 - Compiling Embedded M-Files

2 Installation and Configuration2-10On UNIX, MEX-files are created with platform-specific extensions, as shown in Table 2-2, MEX-File Extensions for U

Page 217 - Macro Options

UNIX Workstation2-11MATLAB Compiler VerificationVerifying from MATLABOnce you have verified that you can generate MEX-files on your system, you are re

Page 218

2 Installation and Configuration2-12Next, verify that invhilb is now a MEX-file by listing the invhilb files:ls invhilb.*You will see a list similar t

Page 219 - Bundle Files

Microsoft Windows on PCs2-13Microsoft Windows on PCsThis section examines the system requirements, installation procedures, and configuration procedur

Page 220

iii3Working with MEX-FilesA Simple Example — The Sierpinski Gasket . . . . . . . . . . . . . 3-2Compiling the M-File into a MEX-File . . . . . . .

Page 221 - Code Generation Options

2 Installation and Configuration2-14Supported ANSI C and C++ PC CompilersTo create C MEX-files, stand-alone C/C++ applications, or dynamically linked

Page 222

Microsoft Windows on PCs2-15Known Compiler Limitations. There are several known restrictions regarding the use of supported compilers:• Some compilers

Page 223

2 Installation and Configuration2-16Compiler Options FilesThe MathWorks provides options files for every supported C or C++ compiler. These files cont

Page 224

Microsoft Windows on PCs2-17created during the -setup process, in a subdirectory of your user profile directory, named Application Data\MathWorks\MATL

Page 225

2 Installation and Configuration2-18Things to Be Aware ofThis table provides information regarding the installation and configuration of a C/C++ compi

Page 226

Microsoft Windows on PCs2-19mex VerificationChoosing a CompilerSystems with Exactly One C/C++ Compiler. If you have properly installed the MATLAB Comp

Page 227

2 Installation and Configuration2-20[1] : Borland compiler in T:\Borland\BC.500[2] : WATCOM compiler in T:\watcom\c.106[0] : NonePlease select a compi

Page 228

Microsoft Windows on PCs2-21[15] Microsoft Visual C/C++ version 5.0[16] WATCOM C/C++ version 11[17] WATCOM C/C++ version 10.6[0] NoneCompiler: 14Your

Page 229

2 Installation and Configuration2-22The setup option copies the appropriate options file to your user profile directory. To make your user-specific ch

Page 230

Microsoft Windows on PCs2-23mex -setup and select Microsoft Visual C/C++ version 5 or 6. For more information about the add-in, see “Using an Integrat

Page 231

iv ContentsBuilding Stand-Alone Applications on PCs . . . . . . . . . . . . . 4-15Configuring for C or C++ . . . . . . . . . . . . . . . . . . . .

Page 232

2 Installation and Configuration2-24Note Before you test to see if the Compiler can generate MEX-files from the DOS command prompt, you may want to d

Page 233

Troubleshooting2-25TroubleshootingThis section identifies some of the more common problems that can occur when installing and configuring the MATLAB C

Page 234

2 Installation and Configuration2-26mex Works from Shell But Not from MATLAB (UNIX). If the commandmex -x yprime.cworks from the UNIX shell prompt but

Page 235

Troubleshooting2-27Troubleshooting the CompilerOne problem that might occur when you try to use the Compiler involves licensing.Licensing Problem. If

Page 236

2 Installation and Configuration2-28

Page 237 - Quick Reference

3Workingwith MEX-FilesThis chapter gets you started compiling M-files with the MATLAB Compiler.A Simple Example — The Sierpinski Gasket (p. 3-2)Creat

Page 238 - Common Uses of the Compiler

3 Working with MEX-Files3-2A Simple Example — The Sierpinski GasketConsider an M-file function called gasket.m:function theImage = gasket(numPoints)%G

Page 239

A Simple Example — The Sierpinski Gasket3-3The curve can be graphed in many ways. Sierpinski's method is• Start with a triangle and from it remov

Page 240

3 Working with MEX-Files3-4This example uses the -x macro option to create the MEX-file. For more information on this Compiler option, see the mcc ref

Page 241

A Simple Example — The Sierpinski Gasket3-5Figure 3-1, The Sierpinski Gasket for 50,000 Points, shows the results.Figure 3-1: The Sierpinski Gasket f

Page 242

v5Controlling Code GenerationCode Generation Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-2Example M-Files . . . . . . . .

Page 243

3 Working with MEX-Files3-6Compiler Options and MacrosThe MATLAB Compiler uses a family of options, also called option flags, to control the functiona

Page 244

Generating Simulink S-Functions3-7Generating Simulink S-FunctionsYou can use the MATLAB Compiler to generate Simulink C MEX S-functions. This allows y

Page 245 - Messages

3 Working with MEX-Files3-8The result is an S-function described in the following files:mfilename.cmfilename.hmfilename_simulink.cmfilename.ext(where

Page 246 - B Error and Warning Messages

Generating Simulink S-Functions3-9Data TypeThe input and output vectors for the Simulink S-function must be double-precision vectors or scalars. You m

Page 247 - Compile-Time Errors

3 Working with MEX-Files3-10Converting Script M-Files to Function M-FilesMATLAB provides two ways to package sequences of MATLAB commands:• Function M

Page 248

Converting Script M-Files to Function M-Files3-11in the MATLAB workspace. If it is important to have m accessible from the MATLAB workspace, you can c

Page 249

3 Working with MEX-Files3-12

Page 250

4 Stand-AloneApplicationsThis chapter explains how to use the MATLAB Compiler to code and build stand-alone applications.Stand-alone applications run

Page 251

4 Stand-Alone Applications4-2Differences Between MEX-Files and Stand-Alone ApplicationsMEX-files and stand-alone applications differ in these respects

Page 252

Differences Between MEX-Files and Stand-Alone Applications4-3For more information about distributing a C application, see “Distributing Stand-Alone Ap

Page 253

vi ContentsInterfacing M-Code to C/C++ Code . . . . . . . . . . . . . . . . . . . . . 5-46C Example . . . . . . . . . . . . . . . . . . . . . . .

Page 254

4 Stand-Alone Applications4-4Building Stand-Alone C/C++ ApplicationsThis section explains how to build stand-alone C and C++ applications on UNIX syst

Page 255 - Warning Messages

Building Stand-Alone C/C++ Applications4-5Figure 4-1, Sequence for Creating Stand-Alone C/C++ Applications, shows the sequence on both platforms. The

Page 256

4 Stand-Alone Applications4-6Getting StartedIntroducing mbuildThe MathWorks utility, mbuild, lets you customize the configuration and build process. T

Page 257

Building Stand-Alone Applications on UNIX4-7Building Stand-Alone Applications on UNIXThis section explains how to compile and link C or C++ source cod

Page 258

4 Stand-Alone Applications4-8Locating Options Filesmbuild locates your options file by searching the following:• The current directory•$HOME/.matlab/R

Page 259

Building Stand-Alone Applications on UNIX4-9The setup option creates a user-specific options file for your ANSI C or C++ compiler. Executing mbuild -s

Page 260

4 Stand-Alone Applications4-10the current linker settings, or you want to disable a particular set of warnings, you should use the setup option.If you

Page 261

Building Stand-Alone Applications on UNIX4-11Verifying mbuildThere is C source code for an example ex1.c included in the <matlab>/extern/example

Page 262

4 Stand-Alone Applications4-12be found and loaded. Consequently, to share a Compiler-generated, stand-alone application with another user, you must pr

Page 263 - Run-Time Errors

Building Stand-Alone Applications on UNIX4-13About the mbuild ScriptThe mbuild script supports various options that allow you to customize the buildin

Page 264

viiAMATLAB Compiler Quick ReferenceCommon Uses of the Compiler . . . . . . . . . . . . . . . . . . . . . . . . . A-2mcc . . . . . . . . . . . . .

Page 265

4 Stand-Alone Applications4-14Note If you distribute an application created with the math libraries on Digital UNIX, your users must have both the C+

Page 266

Building Stand-Alone Applications on PCs4-15Building Stand-Alone Applications on PCsThis section explains how to compile and link the C/C++ code gener

Page 267

4 Stand-Alone Applications4-16Note You can override the language choice that is determined from the extension by using the -lang option of mbuild. Fo

Page 268

Building Stand-Alone Applications on PCs4-17Choosing a CompilerSystems with Exactly One C/C++ Compiler. If the MATLAB Compiler and your supported C or

Page 269

4 Stand-Alone Applications4-18[1] Lcc C version 2.4 in D:Applications\Mathworks\sys\lcc [2] Microsoft Visual C/C++ version 6.0 in D:\Applications\Micr

Page 270

Building Stand-Alone Applications on PCs4-19Compiler: 10Your machine has a Microsoft Visual C/C++ compiler located atD:\Applications\Microsoft Visual

Page 271

4 Stand-Alone Applications4-20specific needs and save the modified file. This sets your default compiler’s options file to your specific version. Tabl

Page 272

Building Stand-Alone Applications on PCs4-21Combining Customized C and C++ Options Files. The options files for mbuild have changed as of MATLAB 5.3 (

Page 273

4 Stand-Alone Applications4-22Verifying mbuildThere is C source code for an example, ex1.c, included in the <matlab>\extern\examples\cmath direc

Page 274

Building Stand-Alone Applications on PCs4-23 1.0000 + 7.0000i 4.0000 +10.0000i 2.0000 + 8.0000i 5.0000 +11.0000i 3.0000 + 9.0000i 6.0000 +

Commentaires sur ces manuels

Pas de commentaire