Main Content

codebuild

Compile and link generated code

Description

example

buildResults = codebuild(buildFolder) loads data from the buildInfo.mat file in buildFolder, generates a makefile in buildFolder, and uses the specified toolchain or template makefile to compile source code that is registered in the RTW.BuildInfo object. If the object is at the top of a hierarchy, the function performs the process for each object in the hierarchy.

The function saves compilation artifacts, including object code files, in buildFolder.

The function returns an object that contains the display output. To view the output, run disp(buildResults).

codebuild(buildFolder, Name,Value) specifies additional options using one or more name-value pairs.

codebuild(buildInfo, Name,Value) compiles the code specified in buildInfo using one or more name-value pairs.

Examples

Relocate and Compile Generated Code

For an example that shows how to relocate and compile generated code in another development environment, see Compile Code in Another Development Environment.

Input Arguments

collapse all

Path to the build folder, which typically contains the generated source code. The folder must contain the buildInfo.mat file.

Example: codebuild(pathToCodeFolder, 'BuildMethod', myToolchain)

RTW.BuildInfo object that contains information for compiling and linking generated code.

Example: codebuild(myBuildInfo, 'BuildMethod','CMake')

Name-Value Arguments

Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside quotes. You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

Example: codebuild(pathToCodeFolder, 'BuildMethod', myToolchain)

Use one these build methods:

  • Toolchain — Specify the name of the toolchain, for example, 'GNU gcc/g++ | gmake (64-bit Linux)'.

  • Template makefile — Specify the path to the template makefile.

  • CMake — Specify 'cmake', which generates CMakeLists.txt configuration files for the CMake build system. The argument value is case-insensitive. For example, you can also specify 'Cmake' or 'CMake'.

Example: codebuild(pathToCodeFolder, 'BuildMethod', 'CMake')

Specify the type of build output:

  • 'STANDALONE_EXECUTABLE' –– Generates a standalone, executable file.

  • 'MODEL_REFERENCE_CODER' –– Generates a static library.

  • 'MEX_FILE' –– Generates a MEX file. Use this value only for building a simulation target, for example, model reference simulation target (ModelReferenceSimTarget) and accelerator mode.

  • 'SHARED_LIBRARY' –– Generates a dynamic library.

  • 'STATIC_LIBRARY' –– Generates a static library.

Example: codebuild(pathToCodeFolder, 'BuildVariant', 'SHARED_LIBRARY')

Output Arguments

collapse all

Capture display output from build process. To view the display output, in the Command Window, run disp(buildResults).

Introduced in R2020b