Paths and File Infrastructure Setup

Compile Path Search Order

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.

Specify Folders to Search for Custom Code

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 foldersDo this
Using the MATLAB Coder app
  1. To open the Generate dialog box, on the Generate Code page, click the Generate arrow .

  2. Click More Settings.

  3. On the Paths tab, in the Search paths field, either browse to add a folder to the search path or enter the full path. The search path must not contain spaces.

At the command lineUse the codegen function -I option.

Naming Conventions

MATLAB Coder enforces naming conventions for MATLAB functions and generated files.

Reserved Prefixes

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.

Reserved Keywords

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 that the code generator cannot rename, 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

assertexternsetjmpstring
autofenvshortstruct
breakfloatsignalswitch
caseforsignedtgmath
chargotosizeofthreads
constifstatictime
complexintstdaligntypedef
continueinttypesstdarguchar
ctypeiso646stdatomicunion
defaultlimitsstdboolunsigned
dolocalestddefvoid
doublelongstdintvolatile
elsemathstdiowchar
enumregisterstdlibwctype
errnoreturnstdnoreturnwhile

C++ Reserved Keywords

algorithmcstddefiostreamsstream
anycstdintistreamstack
arraycstdioiteratorstatic_cast
atomiccstdliblimitsstdexcept
bitsetcstringliststreambuf
cassertctgmathlocalestring_view
catchctimemapstrstream
ccomplexcucharmemorysystem_error
cctypecwcharmemory_resourcetemplate
cerrnocwctypemutablethis
cfenvdeletemutexthread
cfloatdequenamespacethrow
chronodynamic_castnewtry
cinttypesexceptionnumerictuple
ciso646executionoperatortypeid
classexplicitoptionaltype_traits
climitsexportostreamtypeindex
clocalefilesystemprivatetypeinfo
cmathforeward_listprotectedtypename
codecvtfriendpublicunordered_map
complexfstreamqueueunordered_set
condition_variablefunctionalrandomusing
const_castfutureratioutility
csetjmpinitializer_listregexvalarray
csignalinlinereinterpret_castvector
cstdaligniomanipscoped_allocatorvirtual
cstdargiossetwchar_t
cstdbooliosfwdshared_mutex 

Reserved Keywords for Code Generation

absfortranlocalZCErtNaN
asmHAVESTDIOlocalZCSVSeedFileBuffer
boolid_tmatrixSeedFileBufferLen
boolean_Tint_TMODELsingle
byte_T int8_TMTTID01EQ
char_Tint16_TNCSTATEStime_T
cint8_Tint32_TNULLtrue
cint16_Tint64_TNUMSTTRUE
cint32_TINTEGER_CODEpointer_Tuint_T
creal_TLINK_DATA_BUFFER_SIZEPROFILING_ENABLED uint8_T
creal32_TLINK_DATA_STREAMPROFILING_NUM_SAMPLESuint16_T
creal64_TlocalBreal_Tuint32_T
cuint8_TlocalCreal32_Tuint64_T
cuint16_TlocalDWorkreal64_TUNUSED_PARAMETER
cuint32_TlocalPRTUSE_RTMODEL
ERTlocalXRT_MALLOC VCAST_FLUSH_DATA
falselocalXdisrtInfvector
FALSElocalXdotrtMinusInf 

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 crviewer.

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 $N, for example, 'rt_atan2$N'. $N expands into the suffix _snf only if nonfinite numbers are supported. For example, 'rt_atan2$N' represents 'rt_atan2_snf' if nonfinite numbers are supported and 'rt_atan2' if nonfinite numbers are not supported. As a precaution, you should treat both forms of the keyword as reserved.

Conventions for Naming Generated Files

The following table describes how MATLAB Coder names generated files. MATLAB Coder follows MATLAB conventions by providing platform-specific extensions for MEX files.

PlatformMEX File ExtensionMATLAB Coder Extension for Static LibraryMATLAB Coder Extension for Shared LibraryMATLAB Coder Executable Extension
Linux® (64-bit).mexa64.a.soNone
Mac (64-bit).mexmaci64.a.dylibNone
Windows® (64-bit).mexw64.lib.dll
Also, generates an import library with a .lib extension that is required for linking against the .dll.
.exe