title: Swift Package Manager dynamic library
body: <p>I've recently converted a bunch of my frameworks to use Swift Package Manager. My <code>Package.swift</code> looks something like this:</p>
  
  <pre><code>// swift-tools-version:5.1
  import PackageDescription
  
  let package = Package(
      name: "MDFToolbox",
      platforms: [
          .macOS(.v10_13), .iOS(.v12), .tvOS(.v12), .watchOS(.v3)
      ],
      products: [
          .library(name: "MDFToolbox", targets: ["MDFToolbox"])
      ],
      dependencies: [
          .package(url: "git@github.com:Swinject/Swinject.git", from: "2.7.0"),
      ],
      targets: [
          .target(name: "MDFToolbox", dependencies: ["Swinject"]),
      ]
  )
  </code></pre>
  
  <p>Since the library used to be a framework, I'd like to link it in my app as a dynamic library (<code>.dylib</code>). According to the library product definition in the Package documentation, I can specify the <code>type</code> of my library to be <code>.dynamic</code> if I want:</p>
  
  <blockquote>
    <p>The optional type of the library that is used to determine how to link to the library. Leave this parameter unspecified to let to let the Swift Package Manager choose between static or dynamic linking (recommended). If you do not support both linkage types, use .static or .dynamic for this parameter.</p>
  </blockquote>
  
  <p>If I leave it as <code>nil</code>, Xcode defaults to building a static library when I link this package in my app project, which is not what I want. </p>
  
  <p>If I set the type to <code>.dynamic</code> in my library's Package.swift, Xcode builds a <code>.dylib</code>, but it doesn't get embedded in the application, leading to a linker error:</p>
  
  <pre><code>dyld: Library not loaded: @rpath/libMDFToolbox.dylib
    Referenced from: /Users/mpdifran/Library/Developer/Xcode/DerivedData/Remind-eewbkbjpfrqbdwchjrbmrtxzsjew/Build/Products/Debug-maccatalyst/Remind.app/Contents/MacOS/Remind
    Reason: no suitable image found.  Did find:
      /Users/mpdifran/Library/Developer/Xcode/DerivedData/Remind-eewbkbjpfrqbdwchjrbmrtxzsjew/Build/Products/Debug-maccatalyst/libMDFToolbox.dylib: code signature in (/Users/mpdifran/Library/Developer/Xcode/DerivedData/Remind-eewbkbjpfrqbdwchjrbmrtxzsjew/Build/Products/Debug-maccatalyst/libMDFToolbox.dylib) not valid for use in process using Library Validation: mapped file has no cdhash, completely unsigned? Code has to be at least ad-hoc signed.
  </code></pre>
  
  <p>I also see no easy way of adding the <code>.dylib</code> to a Copy Files Build Phase...</p>
  
  <p>So what's the recommended way of asking SPM to build and link a dynamic library through Xcode? Is this something that is not yet supported?</p>