MATLAB® Coder™ resolves MATLAB functions by searching first on the code generation path and then on the MATLAB path. The code generation path contains the current folder and the code generation libraries. By default, unless MATLAB Coder determines that a function should be extrinsic or you explicitly declare the function to be extrinsic, MATLAB Coder tries to compile and generate code for functions it finds on the path. MATLAB Coder does not compile extrinsic functions, but rather dispatches them to MATLAB for execution. See Resolution of Function Calls for Code Generation.
If you want to integrate custom code — such as source, header, and library files — with the generated code, you can specify additional folder to search. The following table describes how to specify these search paths. The path should not contain:
Spaces (Spaces can lead to code generation failures in certain operating system configurations)
Tabs
\
, $
, #
, *
, ?
Non-7-bit ASCII characters, such as Japanese characters
To specify additional folders | Do this |
---|---|
Using the MATLAB Coder app |
|
At the command line | Use the codegen function -I option. |
MATLAB Coder enforces naming conventions for MATLAB functions and generated files.
MATLAB Coder reserves the prefix eml
for
global C/C++ functions and variables in generated code. For example, MATLAB for
code generation run-time library function names begin with the prefix emlrt
,
such as emlrtCallMATLAB
. To avoid naming conflicts,
do not name C/C++ functions or primary MATLAB functions with
the prefix eml
.
MATLAB Coder software reserves certain words for its own use as keywords of the generated code language. MATLAB Coder keywords are reserved for use internal to MATLAB Coder software and should not be used in MATLAB code as identifiers or function names. C reserved keywords should also not be used in MATLAB code as identifiers or function names. If your MATLAB code contains reserved keywords, the code generation build does not complete and an error message is displayed. To address this error, modify your code to use identifiers or names that are not reserved.
If you are generating C++ code using the MATLAB Coder software, in addition, your MATLAB code must not contain the C++ Reserved Keywords.
C Reserved Keywords
auto | double | int | struct |
break | else | long | switch |
case | enum | register | typedef |
char | extern | return | union |
const | float | short | unsigned |
continue | for | signed | void |
default | goto | sizeof | volatile |
do | if | static | while |
C++ Reserved Keywords
catch | friend | protected | try |
class | inline | public | typeid |
const_cast | mutable | reinterpret_cast | typename |
delete | namespace | static_cast | using |
dynamic_cast | new | template | virtual |
explicit | operator | this | wchar_t |
export | private | throw |
Reserved Keywords for Code Generation
abs | fortran | localZCE | rtNaN |
asm | HAVESTDIO | localZCSV | SeedFileBuffer |
bool | id_t | matrix | SeedFileBufferLen |
boolean_T | int_T | MODEL | single |
byte_T | int8_T | MT | TID01EQ |
char_T | int16_T | NCSTATES | time_T |
cint8_T | int32_T | NULL | true |
cint16_T | int64_T | NUMST | TRUE |
cint32_T | INTEGER_CODE | pointer_T | uint_T |
creal_T | LINK_DATA_BUFFER_SIZE | PROFILING_ENABLED | uint8_T |
creal32_T | LINK_DATA_STREAM | PROFILING_NUM_SAMPLES | uint16_T |
creal64_T | localB | real_T | uint32_T |
cuint8_T | localC | real32_T | uint64_T |
cuint16_T | localDWork | real64_T | UNUSED_PARAMETER |
cuint32_T | localP | RT | USE_RTMODEL |
ERT | localX | RT_MALLOC | VCAST_FLUSH_DATA |
false | localXdis | rtInf | vector |
FALSE | localXdot | rtMinusInf |
MATLAB Coder Code Replacement Library Keywords. The list of code replacement library (CRL) reserved keywords for your development environment varies depending on which CRLs currently are registered. Beyond the default ANSI®, ISO®, and GNU® CRLs provided with MATLAB Coder software, additional CRLs might be registered and available for use if you have installed other products that provide CRLs (for example, a target product), or if you have used Embedded Coder® APIs to create and register custom CRLs.
To generate a list of reserved keywords for the CRLs currently registered in your environment, use the following MATLAB function:
crl_ids = RTW.TargetRegistry.getInstance.getTflReservedIdentifiers()
This function returns a cell array of character vectors that contain CRL keywords. Specifying the return argument is optional.
Note:
To list the CRLs currently registered in your environment, use
the MATLAB command |
To generate a list of reserved keywords for the CRL that you are using to generate code, call the function passing the name of the CRL as displayed in the Code replacement library menu on the Code Generation > Interface pane of the Configuration Parameters dialog box. For example,
crl_ids = RTW.TargetRegistry.getInstance.getTflReservedIdentifiers('GNU99 (GNU)')
Here is a partial example of the function output:
>> crl_ids = RTW.TargetRegistry.getInstance.getTflReservedIdentifiers('GNU99 (GNU)') crl_ids = 'exp10' 'exp10f' 'acosf' 'acoshf' 'asinf' 'asinhf' 'atanf' 'atanhf' ... 'rt_lu_cplx' 'rt_lu_cplx_sgl' 'rt_lu_real' 'rt_lu_real_sgl' 'rt_mod_boolean' 'rt_rem_boolean' 'strcpy' 'utAssert'
Note:
Some of the returned keywords appear with the suffix |
The following table describes how MATLAB Coder names generated files. MATLAB Coder follows MATLAB conventions by providing platform-specific extensions for MEX files.
Platform | MEX File Extension | MATLAB Coder Extension for Static Library | MATLAB Coder Extension for Shared Library | MATLAB Coder Executable Extension |
---|---|---|---|---|
Linux® (64-bit) | .mexa64 | .a | .so | None |
Apple Mac (64-bit) | .mexmaci64 | .a | .dylib | None |
Windows® (64-bit) | .mexw64 | .lib | .dll Also, generates an import library with a .lib extension that is required
for linking against the .dll . | .exe |