<!--
{
  "documentType" : "article",
  "framework" : "Metal",
  "identifier" : "/documentation/Metal/metal-dynamic-libraries",
  "metadataVersion" : "0.1.0",
  "role" : "collectionGroup",
  "title" : "Metal dynamic libraries"
}
-->

# Metal dynamic libraries

Create a single Metal library containing reusable code to reduce library size and avoid repeated shader compilation at runtime.

## Discussion

As shaders grow in size, complexity, and scope, they often end up sharing utility functions. Under the default compilation model in Metal, linking embeds libraries, similar to static linking with the LLVM linker. For Metal, embedding libraries in this manner has two consequences: an increase in binary size, and an increase in compilation time. As each library loads, it compiles its own version of any utility functions, meaning Metal compiles and duplicates your utility functions multiple times.

To avoid this problem, Metal offers dynamic libraries, similar to an LLVM dynamically shared library. Your app loads and compiles dynamic libraries for the device GPU once, the first time a shader requests them. Subsequent shader calls use these compiled utility functions instead of compiling a separate version of the same shader binary.

To support Metal dynamic libraries in your app, call [`makeDynamicLibrary(library:)`](/documentation/Metal/MTLDevice/makeDynamicLibrary(library:)) with a dynamic library that you bundle as part of your app. Then add it to a pipeline descriptor’s dynamic library information through a property like [`preloadedLibraries`](/documentation/Metal/MTLComputePipelineDescriptor/preloadedLibraries).

## Topics

### Working with Metal dynamic libraries

[Compiling and linking Metal dynamic libraries](/documentation/Metal/compiling-and-linking-metal-dynamic-libraries)

Build a Metal dynamic library from the command line, allowing for runtime loading of shared shaders.

[Creating a Metal dynamic library](/documentation/Metal/creating-a-metal-dynamic-library)

Compile a library of shaders and write it to a file as a dynamically linked library.



---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)