主要内容

Set MATLAB Library Paths for Testing Deployed Applications

Note

If you're preparing your application for end-user deployment rather than development testing, see Set MATLAB Runtime Library Paths for Deployment.

When developing applications with MATLAB® Compiler™ or MATLAB Compiler SDK™, use your existing MATLAB installation instead of a separate MATLAB Runtime installation for testing. This approach reduces development time and maintains consistency between development and testing environments.

The development cycle typically involves compiling, testing, debugging, and recompiling applications multiple times. Configure your system to use the libraries from your MATLAB installation to test your compiled applications without installing and configuring MATLAB Runtime for each test iteration.

On the development machine, you can test your application's execution by issuing !application-name at the MATLAB prompt. This will verify that library dependencies are correct, that the deployable archive can be extracted, and that all MATLAB code, MEX—files and support files required by the application have been included in the archive. To test applications using MATLAB from the system command line, follow the instructions in this topic to configure your system library path for testing with your MATLAB installation. This configuration uses the same core libraries that MATLAB Runtime provides, but accesses them directly from your MATLAB installation folders. The final deployed application requires MATLAB Runtime on end-user systems.

Library Path Environment Variables and MATLAB Folders

Operating SystemEnvironment VariableFolders
Windows®PATHmatlabroot\runtime\win64
Linux®LD_LIBRARY_PATH

matlabroot/runtime/glnxa64

matlabroot/bin/glnxa64

matlabroot/sys/os/glnxa64

matlabroot/extern/bin/glnxa64

macOS (Apple silicon)DYLD_LIBRARY_PATH

matlabroot/runtime/maca64

matlabroot/bin/maca64

matlabroot/sys/os/maca64

matlabroot/extern/bin/maca64

Windows

To configure your Windows system to use MATLAB installation libraries for testing packaged applications:

  1. Determine your MATLAB installation directory by running the matlabroot command in the MATLAB Command Window.

  2. Run C:\Windows\System32\SystemPropertiesAdvanced.exe and click the Environment Variables button.

  3. Select the system variable Path and click Edit.

    Note

    If you do not have administrator rights, select the user variable Path instead.

  4. Click New and add the folder <MATLAB_INSTALL_DIR>\runtime\win64. For example if using MATLAB R2026a in the default location:

    C:\Program Files\MATLAB\R2026a\runtime\win64
    
  5. Click OK to apply the change.

  6. Verify the configuration by opening a new Command Prompt window and running:

    echo %PATH%
    

Note

If multiple MATLAB versions exist in your PATH, applications use the first version listed. Ensure your development version appears first for consistent testing.

Linux

To configure your Linux system to use MATLAB installation libraries for testing packaged applications:

  1. Determine your MATLAB installation directory by running the matlabroot command in the MATLAB Command Window.

  2. Display the current value of LD_LIBRARY_PATH in the terminal:

    echo $LD_LIBRARY_PATH
    
  3. Append the MATLAB library folders to the LD_LIBRARY_PATH variable for the current session:

    export LD_LIBRARY_PATH="${LD_LIBRARY_PATH:+${LD_LIBRARY_PATH}:}\
    <MATLAB_INSTALL_DIR>/runtime/glnxa64:\
    <MATLAB_INSTALL_DIR>/bin/glnxa64:\
    <MATLAB_INSTALL_DIR>/sys/os/glnxa64:\
    <MATLAB_INSTALL_DIR>/extern/bin/glnxa64"
    

    For example, if your MATLAB is installed in /usr/local/MATLAB/R2026a:

    export LD_LIBRARY_PATH="${LD_LIBRARY_PATH:+${LD_LIBRARY_PATH}:}\
    /usr/local/MATLAB/R2026a/runtime/glnxa64:\
    /usr/local/MATLAB/R2026a/bin/glnxa64:\
    /usr/local/MATLAB/R2026a/sys/os/glnxa64:\
    /usr/local/MATLAB/R2026a/extern/bin/glnxa64"
    
  4. Verify the updated path:

    echo $LD_LIBRARY_PATH
    
  5. Check your GNU C library (glibc) version:

    ldd --version
    

    If the version is 2.17 or lower, add the glibc shim to the LD_PRELOAD environment variable:

    export LD_PRELOAD="${LD_PRELOAD:+${LD_PRELOAD}:}\
    <MATLAB_INSTALL_DIR>/bin/glnxa64/glibc-2.17_shim.so"
    

Note

Add <MATLAB_INSTALL_DIR>/sys/opengl/lib/glnxa64 to your LD_LIBRARY_PATH if you encounter graphics issues.

These instructions are for the Bash shell. For other shells, refer to your shell documentation.

macOS

To configure your macOS system to use MATLAB installation libraries for testing compiled applications:

  1. Determine your MATLAB installation directory by running the matlabroot command in the MATLAB Command Window.

  2. Display the current value of LD_LIBRARY_PATH in the terminal:

    echo $DYLD_LIBRARY_PATH
    
  3. Append the MATLAB library folders to DYLD_LIBRARY_PATH:

    export DYLD_LIBRARY_PATH="${DYLD_LIBRARY_PATH:+${DYLD_LIBRARY_PATH}:}\
    <MATLAB_INSTALL_DIR>/runtime/maca64:\
    <MATLAB_INSTALL_DIR>/bin/maca64:\
    <MATLAB_INSTALL_DIR>/sys/os/maca64:\
    <MATLAB_INSTALL_DIR>/extern/bin/maca64"
    

    For example, with MATLAB installed in /Applications/MATLAB_R2026a.app:

    export DYLD_LIBRARY_PATH="${DYLD_LIBRARY_PATH:+${DYLD_LIBRARY_PATH}:}\
    /Applications/MATLAB_R2026a.app/runtime/maca64:\
    /Applications/MATLAB_R2026a.app/bin/maca64:\
    /Applications/MATLAB_R2026a.app/sys/os/maca64:\
    /Applications/MATLAB_R2026a.app/extern/bin/maca64"
    
  4. Verify the updated path:

    echo $DYLD_LIBRARY_PATH
    

These instructions are for the Bash or Zsh shell. For other shells, refer to your shell documentation.

Note

On macOS, System Integrity Protection (SIP) may prevent DYLD_LIBRARY_PATH from being passed to child processes. You may need to run your application from the same terminal session where you set the environment variable.

Set Library Paths Permanently

While setting paths temporarily is recommended for testing, you can set them permanently if needed:

Windows

The permanent PATH setting is already covered in the Windows section using the System Properties dialog.

Linux and macOS

To set library paths permanently on Linux or macOS:

  1. Determine your shell by running:

    echo $SHELL
    
  2. Add the export commands to your shell configuration file:

    • For bash shell, edit ~/.bash_profile or ~/.bashrc and add the appropriate export commands from the Linux or macOS sections above.

    • For Zsh, edit ~/.zprofile or ~/.zshrc and add the appropriate export commands from the Linux or macOS sections above.

  3. Save the file and reload it.

    source ~/.bashrc  # For Bash
    source ~/.zshrc   # For Zsh
    

Caution

Setting MATLAB library paths permanently may cause conflicts with other applications that use the same library paths. Consider these alternatives:

  • Set paths only for the current session during testing.

  • Use application-specific wrapper scripts that set the environment before execution.

For production deployment, always use MATLAB Runtime instead of relying on a MATLAB installation. For details, see Set MATLAB Runtime Library Paths for Deployment.

See Also

Topics