DEADBEEF
DEADBEEF

Reputation: 2290

How to link binary with libraries with SPM and Xcode11

I started to use xcode 11 and I really like the new feature Swift Package Manger. I'm currently moving 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: [
    .library(
      name: "MyFrameworkSDK",
      targets: ["MyFrameworkSDK"]
    ),
  ],
  dependencies: [
    .package(url: "https://github.com/Alamofire/Alamofire", from: "4.9.0"),
    .package(url: "https://github.com/realm/realm-cocoa", from: "3.19.0"),
    .package(url: "https://github.com/SwiftyJSON/SwiftyJSON", from: "5.0.0")
  ],
  targets: [
    .target(
      name: "CPP",
      path: "Sources/CPP",
      cxxSettings: [
        .headerSearchPath("signalProcessingSDK/include/SignalProcessing"),
        .headerSearchPath("signalProcessingSDK/include/MyCPPSDK"),
        .headerSearchPath("signalProcessingSDK/include"),
        .headerSearchPath("CPPSignalProcessing/Codebridge"), // objective-c++ bridge
        .headerSearchPath("CPPSignalProcessing/SignalProcessing.Cpp")
      ],
      linkerSettings: [
        .unsafeFlags(["-LsignalProcessingSDK/lib", "-llibAlgebra"]) // Thise line seems not to work in the client project
      ]
    ),
    .target(
      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?

Upvotes: 3

Views: 1886

Answers (1)

gaussblurinc
gaussblurinc

Reputation: 3692

unsafeFlags is an option to pass arbitrary flags. But you have to pass them in "command line" manner.

["-L", "signalProcessingSDK/lib", "-l", "libAlgebra"]

But I suppose that "relative paths" may be not the right choice for you.

Upvotes: 0

Related Questions