Main Content

Custom Toolchain Registration

What Is a Custom Toolchain?

You can add support for software build tools to MATLAB® Coder™ software. For example, you can add support for a third-party compiler/linker/archiver (toolchain) to your MATLAB Coder software. This customization can be useful when the added toolchain has support and optimizations for a specific type of processor or hardware. These added toolchains are called custom toolchains.

What Is a Factory Toolchain?

MATLAB Coder software includes factory-default support for a set of toolchains. These toolchains are called factory toolchains to distinguish them from custom toolchains. If you install factory toolchains on your host computer, MATLAB Coder can automatically detect and use them. Support for factory toolchains depends on the host operating system. Toolchains are identified by the compiler in the toolchain. A complete list of supported toolchains (compilers) is available at https://www.mathworks.com/support/compilers/.

What is a Toolchain Definition?

A toolchain definition provides MATLAB Coder software with information about the software build tools, such as the compiler, linker, archiver. MATLAB Coder software uses this information, along with a configuration object or project, to build the generated code. This approach can be used when generating static libraries, dynamic libraries, and executables. MEX-file generation uses a different approach. To specify which compiler to use for MEX-function generation, see Setting Up the C or C++ Compiler.

MATLAB Coder software comes with a set of registered factory toolchain definitions. You can create and register custom toolchain definitions. You can customize and manage toolchain definitions. You can share custom toolchain definitions with others running MATLAB Coder software.

If you install toolchain software for one of the factory toolchains, MATLAB Coder can automatically detect and use the toolchain software. For more information about factory toolchains in MATLAB Coder software, see https://www.mathworks.com/support/compilers/.

Key Terms

It is helpful to understand the following concepts:

  • Toolchain — Software that can create a binary executable and libraries from source code. A toolchain can include:

    • Prebuild tools that set up the environment

    • Build tools, such as an Assembler, C compiler, C++ Compiler, Linker, Archiver, that build a binary executable from source code

    • Postbuild tools that clean up the environment

  • Custom toolchain — A toolchain that you define and register for use by MATLAB Coder software

  • Factory toolchains — Toolchains that are predefined and registered in MATLAB Coder software

  • Registered toolchains — The sum of custom and factory toolchain definitions registered in MATLAB Coder software

  • ToolchainInfo object — An instance of the coder.make.ToolchainInfo class that contains a toolchain definition. You save the ToolchainInfo object as a MAT file, register the file with MATLAB Coder. Then you can configure MATLAB Coder to load the ToolchainInfo object during code generation.

  • Toolchain definition file — A MATLAB file that defines the properties of a toolchain. You use this file to create a ToolchainInfo object.

Note

This documentation also refers to the ToolchainInfo object as a coder.make.ToolchainInfo object.

Typical Workflow

The typical workflow for creating and using a custom toolchain definition is:

  1. Create and Edit Toolchain Definition File

    1. Create a toolchain definition file that returns a coder.make.ToolchainInfo object.

    2. Update the file with information about the custom toolchain.

  2. Create and Validate ToolchainInfo Object

    1. Use the toolchain definition file to create a ToolchainInfo object in the MATLAB workspace.

    2. Validate the ToolchainInfo object.

    3. Fix validation issues by updating the toolchain definition file, and creating/validating the updated ToolchainInfo object.

    4. Create a valid ToolchainInfo object and save it to a MAT-file.

  3. Register the Custom Toolchain

    1. Create an rtwTargetInfo.m file and update it with information about the MAT-file.

    2. Register the custom toolchain in MATLAB Coder software using the rtwTargetInfo.m file.

  4. Use the Custom Toolchain

    1. Configure MATLAB Coder software to use the custom toolchain.

    2. Build and run an executable using the custom toolchain.

This workflow requires an iterative approach, with multiple cycles to arrive at a finished version of the custom ToolchainInfo object. You will need access to detailed information about the custom toolchain.

For a tutorial example of this workflow, see Add Custom Toolchains to MATLAB® Coder™ Build Process.

For more information about the ToolchainInfo object, see About coder.make.ToolchainInfo.