Main Content

Build Process Support for Folder Names with Spaces or Special Characters

Folder Names with Spaces

On a Windows® system, the code generator maps a drive corresponding to the MATLAB® installation folder for either of these conditions:

  • The matlabroot folder is a UNC location.

  • The path the matlabroot folder contains spaces, and the system has no alternative name support.

These folder paths can contain spaces:

  • The path to your MATLAB installation folder (matlabroot). For example, C:\Program Files\MATLAB\R2015b

  • The path to the current working folder where you start the build (pwd). For example, C:\Users\username\Documents\My Work.

  • The path to the installation folder for a compiler that the build process uses.

If your work environment includes one or more of the preceding scenarios, use the following support mechanisms for the build process:

  • If you are using the toolchain approach to build generated code, the system support for spaces in folder names influences toolchain operation:

    • For Linux® systems and Windows systems with 8.3 name creation enabled, the toolchain manages spaces in folder names by using alternative names from the operating system. The toolchain uses the TransformPathsWithSpaces attribute to manage these names.

      addAttribute(toolchainObject, 'TransformPathsWithSpaces', true);

      The security permissions of drives and folders can determine whether the toolchain transforms the path. For example, if the path contains a folder with a security configuration that forbids 8.3 path transformations, the toolchain does not transform the path and the build process produces a warning.

    • For Windows systems with 8.3 name creation disabled, the toolchain manages spaces in folder names by mapping a network drive using a batch file (.bat). This operation requires adding the RequiresBatchFile attribute to the toolchain definition.

      addAttribute(toolchainObject, 'RequiresBatchFile', true);

    When developing a toolchain for a Windows system, set both attributes. For more information about the toolchain attributes, see addAttribute.

  • If you are using the template makefile approach to build generated code, the template makefile (.tmf) requires code to manage spaces in folder names. When the alternative folder names (Windows short names) differ from the file system folder names (Windows long names), add this code to the makefile.

    ALT_MATLAB_ROOT         = |>ALT_MATLAB_ROOT<|
    ALT_MATLAB_BIN          = |>ALT_MATLAB_BIN<|
    !if "$(MATLAB_ROOT)" != "$(ALT_MATLAB_ROOT)"
    MATLAB_ROOT = $(ALT_MATLAB_ROOT)
    !endif
    !if "$(MATLAB_BIN)" != "$(ALT_MATLAB_BIN)"
    MATLAB_BIN = $(ALT_MATLAB_BIN)
    !endif

    When the values of the location tokens are not equal, this code replaces MATLAB_ROOT with ALT_MATLAB_ROOT. The replacement indicates that the path to your MATLAB installation folder includes spaces. This code applies the same type of replacement for MATLAB_BIN with ALT_MATLAB_BIN. The preceding code is specific to nmake. For platform-specific examples, see the supplied template makefiles.

With either build approach, when there is an issue with support for creation of alternate names (short names), build errors can occur on Windows. If a build generates an error message similar to the following message, see Troubleshooting Errors When Folder Names Have Spaces.

NMAKE : fatal error U1073: don't know how to make ' ...

When using operating system commands, such as system or dos, enclose paths that specify executable files or command parameters in double quotes (" "). For example:

system('dir "D:\Applications\Common Files"')

This table provides a summary of build folder support and limitations for Windows.

Build Process FoldersApproach for Paths with UNC or SpacesSupport for Windows

matlabroot folder

The matlabroot value is derived from the MATLAB installation location.

During a build, a UNC location such as:

\\networkdrive\matlab\R20xxb

could be remapped as:

T:\

During a build on a Windows system with short file name (8.3) support (default for Windows using NTFS), the build process uses the Windows API getShortPathName() for the folder location.

During a build on a Windows system without short file name (8.3) support (systems using ReFS or using NTFS with 8.3 support disabled), a location with spaces in the path such as:

C:\Program Files\MATLAB\R20xxb

could be remapped as:

T:\R20xxb

Build process folder support available independent of file system (NTFS or ReFS) or file system configuration for short file name support.

Limitations:

On systems that require drive mapping for the installation location, the build process requires that a drive letter is available for mapping.

On systems without short file name (8.3) support (using ReFS or using NTFS with 8.3 support disabled), the final folder in the installation location cannot contain spaces. For example, a final folder name:

C:\Program Files\MATLAB\R20xxb sp1

is not supported.

Code generation folder

Simulation cache folder

Custom code source file locations—among others, these locations include folders specified by:

  • rtwmakecfg.m

  • Model configuration parameter Additional build information

  • Code replacement library

For UNC locations, build process temporarily maps a drive by using the shell commands pushd and popd.

Build process folder support is available independent of file system (NTFS or ReFS) or file system configuration for short path name support.

For paths with spaces, build process uses the Windows short path name (8.3) by using the Windows API:

getShortPathName()

Build process folder support depends on NTFS file system and requires Windows default support. Registry sets value of 2 or 0 for:

NtfsDisable8dot3NameCreation

Limitations: Build process does not support spaces in the path to these folders for:

  • NTFS file system with short path name support disabled

  • ReFS file system (this file system does not support short path names)

Folder Names with Special Characters

If a build-related folder path contains a Japanese (multibyte) character where the final byte is equal to the 5C hexadecimal character, the build process might produce an error. The make and compiler tools might incorrectly interpret the final byte as the '\' (backslash) character.

Troubleshooting Errors When Folder Names Have Spaces

On Windows, when there is an issue with support for creation of short file names, build process errors can occur. When this issue affects a build, you see an error message similar to:

NMAKE : fatal error U1073: don't know how to make 'C:\Work\My'

This message can occur if a space in the folder name (C:\Work\My Models) prevents the build process from finding the model or a file to build. For descriptions of the build-related folders that are sensitive to a space in the folder name or path, see Folder Names with Spaces.

To avoid issues from folder names with spaces when Windows short file name support for file names is disabled, do not use paths with spaces. For example, install third-party software to paths without spaces. Do not use paths with spaces for folders containing your models, source files, or libraries.

An issue can occur with builds that use folder names with spaces, because it is possible to disable Windows alternate name support. The build process uses this alternate name support on Windows systems. There are many terms for this file, folder, and path alternate name support:

  • 8.3 name

  • DOS path

  • short file name (SFN, ShortFileName)

  • long name alias

  • Windows path alias

Verify the type of file system that the drive uses. In Windows Explorer, right-click the drive icon and select properties.

  • If the file system is ReFS (Resilient File System), it is an issue. The ReFS does not provide short file name support. Except for the MATLAB installation folder, the build process does not support folder names with spaces for the ReFS file system. If your work environment requires short file name support for the build folder or for additional external code folders, do not use ReFS.

  • If the file system is NTFS (New Technology File System), it is possible that the build error is related to a registry setting incompatibility. Continue with troubleshooting steps.

The error could stem from an issue with short file name support on a system using NTFS. Check the Windows registry setting that enables the creation of short names for files, folders, and paths.

  1. Open the Windows command prompt, running as administrator. For example, from the Windows Start menu, type cmd, right-click the cmd.exe icon, and select Run as administrator.

  2. Change to the windows\system32 folder and query the NtfsDisable8dot3NameCreation status by typing:

    > fsutil 8dot3name query
  3. If the registry state of NtfsDisable8dot3NameCreation is not 2, the default (Volume level setting), change the value to 2 by typing:

    > fsutil 8dot3name set 2

    For more information about enabling creation of short names. See https://technet.microsoft.com/en-us/library/ff621566.aspx.

    Changing the registry setting enables creation of short names only for files and folders that are created after the change.

  4. To create short names for files created while short name creation was disabled, at the Windows command line, use the fsutil utility.

    To set the short name, the syntax is:

    > fsutil file setshortname <FileName> <ShortName>

    For example, to create the short name PROGRA~1 for the long name C:\Program Files, type:

    > fsutil file setshortname "C:\Program Files" PROGRA~1

    The C:\Program Files folder name is in quotations because it has spaces.  

  5. To verify that the short name was created, use the dir command with /x option to show short names.

    > dir C:\ /x

See Also

Related Topics

External Websites