# How to \`Always Embed Swift Standard Libraries\`?

**URL:** <https://forums.swift.org/t/how-to-always-embed-swift-standard-libraries/29937>\
**Category:** Using Swift\
**Created:** [October 18, 2019, 3:51pm UTC](https://forums.swift.org/t/how-to-always-embed-swift-standard-libraries/29937 "2019-10-18T15:51:52Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![zsolt.molnar](https://avatars.discourse-cdn.com/v4/letter/z/d2c977/32.png) [@zsolt.molnar](https://forums.swift.org/u/zsolt.molnar)\
**Post date:** [October 18, 2019, 3:51pm UTC](https://forums.swift.org/t/how-to-always-embed-swift-standard-libraries/29937/1 "2019-10-18T15:51:52Z")

</div>

We have CLI tool written in Swift for common usage (Android and iOS developers) on macOS. Android developers without Xcode installation get the following error:

```
dyld: Library not loaded: @rpath/libswiftCore.dylib
Referenced from: ~/git/myClITool/macosBin Reason: image not found
Abort trap: 6

```

We found that enabling `Always Embed Swift Standard Libraries` in Xcode would most likely help, but this CLI tool is exported with SPM, ignoring all Xcode settings.

How can I achieve this build behaviour using SPM only?

---

<div class="post-metadata">

**Author:** ![harlanhaskins](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/harlanhaskins/32/333_2.png) [@harlanhaskins](https://forums.swift.org/u/harlanhaskins)\
**Post date:** [October 18, 2019, 4:24pm UTC](https://forums.swift.org/t/how-to-always-embed-swift-standard-libraries/29937/2 "2019-10-18T16:24:52Z")

</div>

If your developers are using at least macOS 10.14.4, those binaries should be linked against the `libswiftCore.dylib` in the OS, which doesn't need Xcode. What version of macOS are they using?

---

<div class="post-metadata">

**Author:** ![Joe\_Groff](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/joe_groff/32/1929_2.png) [@Joe\_Groff](https://forums.swift.org/u/Joe_Groff)\
**Post date:** [October 18, 2019, 5:51pm UTC](https://forums.swift.org/t/how-to-always-embed-swift-standard-libraries/29937/3 "2019-10-18T17:51:55Z")

</div>

10.14.4 was the first version to have the Swift libraries built into the OS. For older macOS versions, they will need to install the Swift 5 Runtime Support package:

[https://support.apple.com/kb/DL1998?locale=en\_US](https://support.apple.com/kb/DL1998?locale=en_US)

---

<div class="post-metadata">

**Author:** ![mayoff](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/mayoff/32/613_2.png) [@mayoff](https://forums.swift.org/u/mayoff)\
**Post date:** [October 18, 2019, 7:25pm UTC](https://forums.swift.org/t/how-to-always-embed-swift-standard-libraries/29937/4 "2019-10-18T19:25:07Z")

</div>

I ran into a similar problem recently when I rebuilt `protoc-gen-swift` with the Xcode 11.1 toolchain. (That is the Protocol Buffers compiler plugin to generate Swift bindings.)

Previously I built it with Xcode 9.3 on macOS 10.13 using the command `swift build -c release -Xswiftc -static-stdlib`. This gave me an executable that I could copy around and run from any directory on any host.

When I rebuilt it using the Xcode 11.1 toolchain with the same command, I could no longer run it:

```
:; .build/x86_64-apple-macosx/release/protoc-gen-swift
dyld: Library not loaded: @rpath/libswiftCore.dylib
  Referenced from: /Users/rmayoff/P/clarity/protobuf/src/swift-protobuf-1.7.0/.build/x86_64-apple-macosx/release/protoc-gen-swift
  Reason: image not found
Abort trap: 6

```

I had to remove the `-Xswiftc -static-stdlib` flags to get a working executable.

---

<div class="post-metadata">

**Author:** ![Joe\_Groff](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/joe_groff/32/1929_2.png) [@Joe\_Groff](https://forums.swift.org/u/Joe_Groff)\
**Post date:** [October 18, 2019, 7:27pm UTC](https://forums.swift.org/t/how-to-always-embed-swift-standard-libraries/29937/5 "2019-10-18T19:27:44Z")

</div>

`-static-stdlib` is no longer supported, yeah.

---

<div class="post-metadata">

**Author:** ![zsolt.molnar](https://avatars.discourse-cdn.com/v4/letter/z/d2c977/32.png) [@zsolt.molnar](https://forums.swift.org/u/zsolt.molnar)\
**Post date:** [October 18, 2019, 7:53pm UTC](https://forums.swift.org/t/how-to-always-embed-swift-standard-libraries/29937/6 "2019-10-18T19:53:38Z")

</div>

They have various versions of macOS (10.14.0 and above).  
Should I add a package dependency to "libswiftCore.dylib"? Is that even possible?

---

<div class="post-metadata">

**Author:** ![zsolt.molnar](https://avatars.discourse-cdn.com/v4/letter/z/d2c977/32.png) [@zsolt.molnar](https://forums.swift.org/u/zsolt.molnar)\
**Post date:** [October 18, 2019, 7:56pm UTC](https://forums.swift.org/t/how-to-always-embed-swift-standard-libraries/29937/7 "2019-10-18T19:56:31Z")

</div>

My goal is to create a single executable that I can distribute to the team, without additional installation requirements. If "-static-stdlib" is no longer supported, maybe should I add an explicit macOS version requirement? Or is there a better way to achieve the goal?

---

<div class="post-metadata">

**Author:** ![Joe\_Groff](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/joe_groff/32/1929_2.png) [@Joe\_Groff](https://forums.swift.org/u/Joe_Groff)\
**Post date:** [October 18, 2019, 8:03pm UTC](https://forums.swift.org/t/how-to-always-embed-swift-standard-libraries/29937/8 "2019-10-18T20:03:20Z")

</div>

You'll either need to require macOS 10.14.4 or later, or ask your clients to install the Swift Runtime Libraries package on their older macOS versions.
