Build Code in Windows Subsystem for Linux - MATLAB & Simulink (original) (raw)

Main Content

If you install Windows Subsystem for Linux (WSL) on your Windows® computer, you can use CMake toolchain definitions to build generated code in the WSL environment. For example, you can:

For the build process, you can specify:

Set Up Environment

Before you can build generated code, you must follow these steps:

  1. On your Windows computer, install Windows Subsystem for Linux (WSL).
  2. In the WSL environment, install a Linux distribution, for example, Debian®.
  3. In the Linux distribution, install CMake and the required build tools, for example, GNU® Make and GCC and G++ compilers.
  4. Check that you can access the code generation and MATLAB® installation folders on your Windows file system from within the WSL environment. You can provide access to the folders by using the DrvFs file system plugin to create a mount point. For more information, see Mount a Linux disk in WSL 2.
    For example, if both folders are on the C: drive, check that:
    • /mnt/c in the WSL file system points to the C: drive on your Windows file system.
    • The mount point has read/write access.
    • The default user within the WSL environment owns the mount point.

Specify Predefined Toolchain Definition in WSL

Before building generated code, in the Configuration Parameters dialog box:

  1. Set Device vendor toIntel and Device type to x86-64 (Linux 64).
  2. Set Toolchain to GNU gcc/g++ | CMake/gmake (Windows Subsystem for Linux).

When you build your model (Ctrl+B), the build process uses the specified toolchain to build generated code.

Create Custom Toolchain Definition for WSL

This command-line example assumes that:

Define a CMake-based toolchain that runs in WSL.

aarchTc = target.create('Toolchain', ... 'Name', 'GNU gcc/g++ aarch64 | CMake/Ninja', ... 'MakeToolType', 'CMake', ... 'Generator', 'Ninja', ... 'RunsOn', target.ExecutionContext.WSL); aarchTc.HostOperatingSystemSupport = target.HostOperatingSystemSupport.WindowsOnly;

Customize the toolchain to use the cross-compiler.

aarchTc.Builder.CommandLineCacheEntries(end+1) = target.create('CMakeCacheEntry', ... 'Name', 'CMAKE_C_COMPILER', ... 'Value', 'aarch64-linux-gnu-gcc'); aarchTc.Builder.CommandLineCacheEntries(end+1) = target.create('CMakeCacheEntry', ... 'Name', 'CMAKE_CXX_COMPILER', ... 'Value', 'aarch64-linux-gnu-g++'); aarchTc.Builder.CommandLineCacheEntries(end+1) = target.create('CMakeCacheEntry', ... 'Name', 'CMAKE_SYSTEM_NAME', ... 'Value', 'Linux'); aarchTc.Builder.CommandLineCacheEntries(end+1) = target.create('CMakeCacheEntry', ... 'Name', 'CMAKE_FIND_ROOT_PATH', ... 'Value', '/usr/aarch64-linux-gnu'); aarchTc.Builder.CommandLineCacheEntries(end+1) = target.create('CMakeCacheEntry', ... 'Name', 'CMAKE_FIND_ROOT_PATH_MODE_PROGRAM', ... 'Value', 'NEVER'); aarchTc.Builder.CommandLineCacheEntries(end+1) = target.create('CMakeCacheEntry', ... 'Name', 'CMAKE_FIND_ROOT_PATH_MODE_LIBRARY', ... 'Value', 'ONLY'); aarchTc.Builder.CommandLineCacheEntries(end+1) = target.create('CMakeCacheEntry', ... 'Name', 'CMAKE_FIND_ROOT_PATH_MODE_INCLUDE', ... 'Value', 'ONLY');

Add the toolchain definition to the internal database.

In the model configuration, specify the toolchain definition.

modelName = 'myModel'; load_system(modelName); set_param(modelName, ... 'ProdHWDeviceType', 'ARM Compatible->ARM 64-bit (LP64)'); set_param(modelName, ... 'Toolchain', aarchTc.Name);

When you build the model, for example, by runningslbuild(modelName), the build process uses the custom toolchain to build the generated code.

If you want to remove the custom toolchain definition from the internal database, enter these commands.

customToolChainDef = target.get('Toolchain', ... 'GNU gcc/g++ aarch64 | CMake/Ninja'); target.remove(customToolChainDef);

See Also

slbuild | target | target.create | target.Toolchain | target.CMake | target.CMakeBuilder | target.CMakeBuildType | target.CMakeCacheEntry

Topics

External Websites