Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

224
Views
Problem with Frameworks in Command Line Tool

Before everyone starts throwing other stack-overflow and forum posts at me: I looked at them all. None of them are helping.

I have a simple cmd tool called swizzler and want to embed the SwizzleSrc framework in it. I have followed all the tutorials and stack overflows with no luck. Here is what I am getting.

Build

2019-02-07 19:22:46.785680-0500 Terminal[67444:11837029] flock failed to lock maps file: errno = 35
2019-02-07 19:22:46.786939-0500 Terminal[67444:11837029] flock failed to lock maps file: errno = 35

Run

Last login: Thu Feb  7 19:21:08 on ttys018
NAME-iMac:~ NAME$ /Users/NAME/Library/Developer/Xcode/DerivedData/swizzler-aslysekmorknabdslxbxfaeuiztk/Build/Products/Debug/swizzler ; exit;
dyld: Library not loaded: @rpath/SwizzleSrc.framework/Versions/A/SwizzleSrc
  Referenced from: /Users/NAME/Library/Developer/Xcode/DerivedData/swizzler-aslysekmorknabdslxbxfaeuiztk/Build/Products/Debug/swizzler
  Reason: image not found
Abort trap: 6
logout
Saving session...
...copying shared history...
...saving history...truncating history files...
...completed.

[Process completed]

Can someone please help? I have been trying for days with no avail.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

To fix your issue we need to change how Xcode handles Swift Command Line Tool targets by default, specifically the linking convention against the Swift standard libraries.

We need to:

  • embed the Swift standard libraries in your SwizzleSrc framework
  • force your swizzler command line executable to dynamically link all Swift libraries
  • finally, make sure your swizzler executable is then able to find all needed Swift libraries (now placed in the framework target)

Let's get started (assumes you are using Xcode 10.1 or above):

Embedding the Swift Libraries in the Framework

This is pretty straightforward. Change the following Build Settings for the SwizzleSrc framework target:

  • Always Embed Swift Standard Libraries to Yes

Dynamically Linking all Swift Libraries in the Command Line Tool

This is the somewhat tricky part. Add the following User-Defined settings for the swizzler tool target (in the Build Settings):

  • SWIFT_FORCE_DYNAMIC_LINK_STDLIB set to YES
  • SWIFT_FORCE_STATIC_LINK_STDLIB set to NO

(To add a new User-Defined setting just click the + button just below the Build Settings tab title.)

This will ensure your command line executable will dynamically link all Swift libraries instead (i.e., by default they are statically linked). By the way, these exact same settings are used by the Swift Package Manager to fix a related issue.

Update the Runpath for the Command Line Tool

Add the following Runpath Search Path entries for the swizzler tool target (in the Build Settings):

  • @executable_path
  • @executable_path/SwizzleSrc.framework/Versions/Current/Frameworks

Now clean your build folder, rebuild again both targets, and check if this fixed your issue for good ;)

References

For further information, be sure to check the following links as well:

  • How to add a dynamic Swift framework to a Command Line Tool
  • Embedded Swift Frameworks on Command Line Tools
  • macOS Command Line Tool with Swift Cocoa Framework: Library not loaded

I also created a (very!) simple Xcode project demonstrating the steps above:

  • github.com/pmattos/Swift-CLI-with-Framework
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!