# Generating C++ header fails: unable to load standard library for target 'arm64-apple-macosx26.0'

**URL:** <https://forums.swift.org/t/generating-c-header-fails-unable-to-load-standard-library-for-target-arm64-apple-macosx26-0/87666>\
**Category:** Using Swift\
**Tags:** cxx-interop\
**Created:** [June 24, 2026, 6:16pm UTC](https://forums.swift.org/t/generating-c-header-fails-unable-to-load-standard-library-for-target-arm64-apple-macosx26-0/87666 "2026-06-24T18:16:55Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![snej](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/snej/32/365_2.png) [@snej](https://forums.swift.org/u/snej)\
**Post date:** [June 24, 2026, 6:16pm UTC](https://forums.swift.org/t/generating-c-header-fails-unable-to-load-standard-library-for-target-arm64-apple-macosx26-0/87666/1 "2026-06-24T18:16:55Z")

</div>

I'm trying to get started with Swift/C++ interoperability by generating C++ headers for my Swift code. The [official instructions](https://swift.org/documentation/cxx-interop/) say Xcode can do it, but I'm working cross-platform so I don't want to go that route. [Another page](https://www.swift.org/documentation/cxx-interop/project-build-setup#generating-c-header-with-exposed-swift-apis) shows how to make swiftc generate headers:

```swift
swiftc -frontend -typecheck \
       /sources/a.swift /sources/b.swift -module-name SwiftModule \
       -cxx-interoperability-mode=default \
       -emit-clang-header-path SwiftModule-Swift.h

```

When I run this (substituting my real source file of course) I just get:

```swift
<unknown>:0: error: unable to load standard library for target 'arm64-apple-macosx26.0'

```

What's wrong? I'm using the standard Xcode 26.5 Swift toolchain (6.3.2) on macOS 26.5.1.

---

<div class="post-metadata">

**Author:** ![snej](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/snej/32/365_2.png) [@snej](https://forums.swift.org/u/snej)\
**Post date:** [June 24, 2026, 6:25pm UTC](https://forums.swift.org/t/generating-c-header-fails-unable-to-load-standard-library-for-target-arm64-apple-macosx26-0/87666/2 "2026-06-24T18:25:17Z")

</div>

Simply running `swiftc -frontend -typecheck /sources/a.swift` produces the same error.

---

<div class="post-metadata">

**Author:** ![allevato](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/allevato/32/385_2.png) [@allevato](https://forums.swift.org/u/allevato)\
**Post date:** [June 24, 2026, 6:48pm UTC](https://forums.swift.org/t/generating-c-header-fails-unable-to-load-standard-library-for-target-arm64-apple-macosx26-0/87666/3 "2026-06-24T18:48:28Z")

</div>

If you're invoking frontend mode directly, you usually need to pass the `-sdk` location explicitly (the driver infers it if not specified).

But in this case, there's no reason to use `-frontend` here at all; I'm not sure why that page includes it. Does it work if you drop `-frontend`?

---

<div class="post-metadata">

**Author:** ![snej](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/snej/32/365_2.png) [@snej](https://forums.swift.org/u/snej)\
**Post date:** [June 24, 2026, 6:49pm UTC](https://forums.swift.org/t/generating-c-header-fails-unable-to-load-standard-library-for-target-arm64-apple-macosx26-0/87666/4 "2026-06-24T18:49:42Z")

</div>

It gets farther, but fails because it can't find the other modules in my project:

```swift
error: emit-module command failed with exit code 1 (use -v to see invocation)
Sources/Redacted/Database.swift:8:15: error: no such module '_Common'
  6 | //
  7 | 
  8 | public import _Common
    | `- error: no such module '_Common'

```

Do I need to pass every single file in my project on the command line? 😬

---

<div class="post-metadata">

**Author:** ![allevato](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/allevato/32/385_2.png) [@allevato](https://forums.swift.org/u/allevato)\
**Post date:** [June 24, 2026, 6:55pm UTC](https://forums.swift.org/t/generating-c-header-fails-unable-to-load-standard-library-for-target-arm64-apple-macosx26-0/87666/5 "2026-06-24T18:55:32Z")

</div>

If you have other modules (either `.swiftmodule` files or C `.modulemap` files) being imported, you need to pass the paths to those to the driver with `-I`.

---

<div class="post-metadata">

**Author:** ![snej](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/snej/32/365_2.png) [@snej](https://forums.swift.org/u/snej)\
**Post date:** [June 24, 2026, 7:01pm UTC](https://forums.swift.org/t/generating-c-header-fails-unable-to-load-standard-library-for-target-arm64-apple-macosx26-0/87666/6 "2026-06-24T19:01:53Z")

</div>

I'm just a simple guy who types `swift build` and it builds my code. This is a bit over my head.

I see there are `.swiftmodule` files being generated down inside `.build/arm64-apple-macosx/debug/ModuleCache` ... are those the ones you mean?

It sounds like basic C++ interop is requiring me to construct my own enormous build commands like the ones shown in Xcode build logs. There's no support for this in SwiftPM?

Thus far I've been using Xcode with my SwiftPM package without having to have an xcodeproj file. It's generally very nice (I don't miss messing with huge lists of build settings) but using Xcode to create interop headers requires having a project file, which appears to mean I have to set everything up by hand again, creating targets and adding all my source files manually. I wish there were an upgrade process, i.e. generate an xcodeproj from my existing Package.swift file.

---

<div class="post-metadata">

**Author:** ![allevato](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/allevato/32/385_2.png) [@allevato](https://forums.swift.org/u/allevato)\
**Post date:** [June 24, 2026, 7:14pm UTC](https://forums.swift.org/t/generating-c-header-fails-unable-to-load-standard-library-for-target-arm64-apple-macosx26-0/87666/7 "2026-06-24T19:14:48Z")

</div>

`ModuleCache` isn't what you want; it has implicitly compiled modules from the system frameworks (which will be generated automatically for you in a temporary directory if needed, when running `swiftc` yourself). I think the `Modules` directory in the same location has what you need.

Rather than trying to piece together an invocation from scratch, I wonder if you could just wedge the `-emit-clang-header-path` flag into the unsafe settings of the target you're interested in. You wouldn't be able to do anything else with that header in a SwiftPM sense AFAIK, but if you're just looking to inspect it, that ought to spit it out.

---

<div class="post-metadata">

**Author:** ![snej](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/snej/32/365_2.png) [@snej](https://forums.swift.org/u/snej)\
**Post date:** [June 24, 2026, 7:20pm UTC](https://forums.swift.org/t/generating-c-header-fails-unable-to-load-standard-library-for-target-arm64-apple-macosx26-0/87666/8 "2026-06-24T19:20:49Z")

</div>

Thanks for the advice!

Meanwhile I'm reading this extremely depressing [series of blog posts](https://davidederosa.com/cross-platform-swift/build-system-part-one/) by Davide DeRosa about cross-platform Swift, in which he says:

> The first advice I can give if you want to build consistently across platforms is to **avoid SwiftPM** , except for Swift Testing. It’s just not fit for the role yet. XCFrameworks only work on Apple, and binary artifact bundles are on their way, but haven’t been released yet. If you need something that works today, get familiar with swiftc and clang, and switch to CMake with ninja.
> 
> ... At this point, you may come to realize how SwiftPM could lead you to a complex source hierarchy. The highly granular dependency model encouraged by the manifest is a neat abstraction, and works very well for modular Swift-only systems. But when you have to account for C/C++ targets, modulemaps, DocC, and external non-Swift libraries, it makes you want to jump off the nearest cliff without even a goodbye letter.

I've been very happy to have left CMake behind, but now it's returning from the grave...

---

<div class="post-metadata">

**Author:** ![snej](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/snej/32/365_2.png) [@snej](https://forums.swift.org/u/snej)\
**Post date:** [June 25, 2026, 9:06pm UTC](https://forums.swift.org/t/generating-c-header-fails-unable-to-load-standard-library-for-target-arm64-apple-macosx26-0/87666/9 "2026-06-25T21:06:01Z")

</div>

I figured it out (with help from Claude...) For the benefit of anyone finding this later on, the answer is to add `.interoperabilityMode(.Cxx)` to your target's `swiftSettings` in Package.swift. This causes the C++ header to get emitted during `swift build`.

The path of the header varies by architecture, but on my machine the header for a module named `_Core` is at

`.build/arm64-apple-macosx/debug/_Core.build/include/_Core-Swift.h`

---

<div class="post-metadata">

**Author:** ![NotTheNHK](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/notthenhk/32/43199_2.png) [@NotTheNHK](https://forums.swift.org/u/NotTheNHK)\
**Post date:** [June 25, 2026, 9:18pm UTC](https://forums.swift.org/t/generating-c-header-fails-unable-to-load-standard-library-for-target-arm64-apple-macosx26-0/87666/10 "2026-06-25T21:18:42Z")

</div>

To be fair, this is one of the [first things mentioned](https://www.swift.org/documentation/cxx-interop/project-build-setup/#mixing-swift-and-c-using-swift-package-manager) in the article you linked. I think the documentation is pretty good in this particular case.

---

<div class="post-metadata">

**Author:** ![snej](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/snej/32/365_2.png) [@snej](https://forums.swift.org/u/snej)\
**Post date:** [June 27, 2026, 4:32pm UTC](https://forums.swift.org/t/generating-c-header-fails-unable-to-load-standard-library-for-target-arm64-apple-macosx26-0/87666/11 "2026-06-27T16:32:56Z")

</div>

No; actually that page says “Swift Package Manager does not yet provide support for using Swift APIs in C++”, which is what I’m doing, so I didn’t read any further. It sounds as though that statement is obsolete?
