---
title: "makeLibrary(source:options:)"
framework: metal
role: symbol
role_heading: Instance Method
path: "metal/mtldevice/makelibrary(source:options:)"
---

# makeLibrary(source:options:)

Synchronously creates a Metal library instance by compiling the functions in a source string.

## Declaration

```swift
func makeLibrary(source: String, options: MTLCompileOptions?) throws -> any MTLLibrary
```

## Parameters

- `source`: A string that contains source code for one or more Metal functions. For information about writing source in Metal Shading Language (MSL), see the https://developer.apple.com/metal/Metal-Shading-Language-Specification.pdf.
- `options`: An doc://com.apple.metal/documentation/Metal/MTLCompileOptions instance that affects the compilation of the source code in the string.

## Mentioned in

Minimizing the binary size of a shader library

## Return Value

Return Value A new MTLLibrary instance if the method completes successfully; otherwise Swift throws an error and Objective-C returns nil.

## Discussion

Discussion Because there’s no search path to find other functions, the source may only import the Metal default library.

## See Also

### Creating shader libraries

- [makeDefaultLibrary()](metal/mtldevice/makedefaultlibrary().md)
- [makeDefaultLibrary(bundle:)](metal/mtldevice/makedefaultlibrary(bundle:).md)
- [makeLibrary(URL:)](metal/mtldevice/makelibrary(url:).md)
- [makeLibrary(source:options:completionHandler:)](metal/mtldevice/makelibrary(source:options:completionhandler:).md)
- [makeLibrary(stitchedDescriptor:)](metal/mtldevice/makelibrary(stitcheddescriptor:).md)
- [makeLibrary(stitchedDescriptor:completionHandler:)](metal/mtldevice/makelibrary(stitcheddescriptor:completionhandler:).md)
- [makeLibrary(data:)](metal/mtldevice/makelibrary(data:)-7khmh.md)
- [makeLibrary(data:)](metal/mtldevice/makelibrary(data:).md)
- [MTLNewLibraryCompletionHandler](metal/mtlnewlibrarycompletionhandler.md)
- [makeLibrary(filepath:)](metal/mtldevice/makelibrary(filepath:).md)
