<!--
{
  "availability" : [
    "iOS: 18.0.0 -",
    "iPadOS: 18.0.0 -",
    "macCatalyst: 18.0.0 -",
    "macOS: 15.0.0 -",
    "tvOS: 18.0.0 -",
    "visionOS: 2.0.0 -",
    "watchOS: 11.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Accelerate",
  "identifier" : "/documentation/Accelerate/BNNSGraphCompileFromFile(_:_:_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Function",
  "symbol" : {
    "kind" : "Function",
    "modules" : [
      "Accelerate"
    ],
    "preciseIdentifier" : "c:@F@BNNSGraphCompileFromFile"
  },
  "title" : "BNNSGraphCompileFromFile(_:_:_:)"
}
-->

# BNNSGraphCompileFromFile(_:_:_:)

Compiles a source mlmodelc file to a graph object.

```
func BNNSGraphCompileFromFile(_ filename: UnsafePointer<CChar>, _ function: UnsafePointer<CChar>?, _ options: bnns_graph_compile_options_t) -> bnns_graph_t
```

## Parameters

`filename`

The path to the source mlmodelc file.

`function`

The name of the function that this operation compiles. Pass `nil` to specify that the operation compiles all the functions in the source file.

`options`

The compilation options. Pass `nil` to specify that the operation uses the default set of options.

## Return Value

A compiled graph object. If the operation fails, the graph object’s [`data`](/documentation/Accelerate/bnns_graph_t/data) property is `nil`.

## Discussion

Xcode automatically compiles a Core ML model package (files with an `.mlpackage` file extension) into an mlmodelc file. The following code compiles a [`bnns_graph_t`](/documentation/Accelerate/bnns_graph_t) instance from a file named `myModel.mlpackage` that you copy into the project.

```swift
let options = BNNSGraphCompileOptionsMakeDefault()
defer {
    BNNSGraphCompileOptionsDestroy(options)
}

guard let fileName = Bundle.main.url(
    forResource: "myModel",
    withExtension: "mlmodelc")?.path() else {
    fatalError()
}

let graph = BNNSGraphCompileFromFile(fileName, 
                                     nil,
                                     options)

if graph.size == 0 {
    fatalError()
}
```

## See Also

  <doc://com.apple.documentation/documentation/CoreML/updating-a-model-file-to-a-model-package>



---

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)