Control Library Location and Naming During Build - MATLAB & Simulink (original) (raw)

When you generate precompiled, non-precompiled, and model reference libraries, you can control the library location and library name by using configuration parameters. These parameters control values in generated makefiles during model builds:

Library Control Parameters

Use the library control parameters to:

Targets can set the parameters inside the system target file (STF) select callback. For example:

function mytarget_select_callback_handler(varargin) hDig=varargin{1}; hSrc=varargin{2}; slConfigUISetVal(hDig, hSrc, 'TargetPreCompLibLocation',... 'c:\mytarget\precomplibs'); slConfigUISetVal(hDig, hSrc, 'TargetLibSuffix',... '_target.library');

The TMF has corresponding expansion tokens:

|>EXPAND_LIBRARY_LOCATION<|
|>EXPAND_LIBRARY_SUFFIX<|

Alternatively, you can use a call to the set_param function. For example:

set_param(model,'TargetPreCompLibLocation',... 'c:\mytarget\precomplibs');

Note

If your model contains referenced models, you can use the make optionUSE_MDLREF_LIBPATHS to control whether libraries used by the referenced models are copied to the build folder of the parent model. For more information, see Location of Model Reference Libraries.

Identify Library File Type for Toolchain Approach

The toolchain approach for model builds does not use the value of theTargetLibSuffix configuration parameter to select the library file name _`suffix`_ and_`extension`_.

With the toolchain approach, the final binary name is composed of the_`modelname`_, the_`compilername`_, and the_`extension`_ provided by the build tool description in the toolchain definition:

model_compilername.extension

You can identify the static library file name extension from the build tool description in the toolchain definition. To get this information for the default toolchain, use this procedure:

  1. Get the default toolchain name. For example, enter:
tc_name = coder.make.getDefaultToolchain()  
  1. Get the default toolchain handle. For example, enter:
    tc = coder.make.getToolchainInfoFromRegistry(tc_name)
  2. Get the handle to the toolchain object. For example, enter:
    tool_archiver = tc.getBuildTool('Archiver');
  3. Get the extension. For example, enter:
    ext_archiver = tool_archiver.getFileExtension('Static Library');

Note

If you do not set the TargetLibSuffix parameter, template makefile and toolchain approaches produce the same static library file name _`extension`_.

Specify the Location of Precompiled Libraries

Use the TargetPreCompLibLocation configuration parameter to:

For a precompiled library, such as a blockset library or the Simulink Coder block library, the location specified inrtwmakecfg.m is typically a location specific to the blockset or the Simulink Coder product. The code generator expects that the library exists in this location and links against the library during builds.

For some applications, such as custom targets, it is preferable to locate the precompiled libraries in a target-specific or other alternate location rather than in the location specified in rtwmakecfg.m. For a custom target, the code generator expects that the target-specific cross-compiler creates the library, and you place the library in the target-specific location. Compile and place libraries supported by the target in the target-specific location, so they can be used during the build process.

You can set up the TargetPreCompLibLocation parameter in its select callback. The path that you specify for the parameter must be a fully qualified, absolute path to the library location. Relative paths are not supported. For example:

slConfigUISetVal(hDlg, hSrc, 'TargetPreCompLibLocation',... 'c:\mytarget\precomplibs');

Alternatively, you set the parameter with a call to theset_param function. For example:

set_param(model,'TargetPreCompLibLocation',... 'c:\mytarget\precomplibs');

During makefile generation, the build process replaces the tokens with the location from the rtwmakecfg.m file. For example, if the library name in the rtwmakecfg.m file is 'rtwlib', the template makefile build approach expands the token from:

LIBS += |>EXPAND_LIBRARY_LOCATION<||>EXPAND_LIBRARY_NAME<|
_target.library

to:

LIBS += c:\mytarget\precomplibs\rtwlib_target.library

By default, TargetPreCompLibLocation is an empty character vector. The build process uses the location in rtwmakecfg.m for the token replacement.

Location of Model Reference Libraries

The build process assigns a path such as../slprj/grt/sub/sub_rtwlib.lib toMODELREF_LINK_LIBS. The build process uses the path to gain access to the library file at link time.

Control the Suffix Applied to Library File Names

With the template makefile approach for model builds, use theTargetLibSuffix configuration parameter to control the suffix applied to library names (for example, _target.lib or_target.a). The specified suffix scheme must include a period (.). You can apply TargetLibSuffix to the following libraries: