How to link binary with libraries with SPM and Xcode11


I started to use xcode 11 and I'm really impressed by the new feature Swift Package Manger I really like it and move some of my project with it.

One of my framework is a a Swift wrapper around c++ libraries. Theses libraries are static libraries and I cannot change it.
I'm trying to configure the Package.swift but I didn't have any success.

I create 2 targets one with all the c++ and objective-c++ files and one other with the Swift file.

My package looks like this:

// swift-tools-version:5.1
import PackageDescription

let package = Package(
  name: "MyFrameworkSDK",
  platforms: [.iOS(.v9)],
  products: [
      name: "MyFrameworkSDK",
      targets: ["MyFrameworkSDK"]
  dependencies: [
    .package(url: "", from: "4.9.0"),
    .package(url: "", from: "3.19.0"),
    .package(url: "", from: "5.0.0")
  targets: [
      name: "CPP",
      path: "Sources/CPP",
      cxxSettings: [
        .headerSearchPath("CPPSignalProcessing/Codebridge"), // objective-c++ bridge
      linkerSettings: [
        .unsafeFlags(["-LsignalProcessingSDK/lib", "-llibAlgebra"]) // Thise line seems not to work in the client project
      name: "MyFrameworkSDK",
      dependencies: ["Alamofire", "RealmSwift", "SwiftyJSON", "CPP"],
      path: "Sources/Swift"
  swiftLanguageVersions: [.v5],
  cxxLanguageStandard: .gnucxx11

I get the following error in the client:

d: warning: directory not found for option '-LsignalProcessingSDK/lib'
ld: library not found for -llibAlgebra

So my questions are:

  1. Is "unsafeFlags" is the right command to use to link binary with libraries? If not what should I use?
  2. Is the path given to "unsafeFlags" absolute or relative to the target?

Thanks for your help.

We don't support including precompiled binaries in Swift packages, yet, except for libraries and frameworks installed on the system. There is a pitch proposal for this feature: [PITCH] Support for binary dependencies

You can use unsafeFlags to still do it, but this will mean your package is not usable as a transitive dependency, so that's not really suitable for your case where you want to provide a framework.

If "signalProcessingSDK" is a set of libraries you are building with a different build system today, you could look into turning it into a package itself.

Terms of Service

Privacy Policy

Cookie Policy