I have 2 Swift packages: OctoIO and Octo.
OctoIO has a product that is a dynamic library and it depends on swift-log:
// swift-tools-version: 5.7
import PackageDescription
let package = Package(
name: "OctoIO",
platforms: [.macOS(.v10_15)],
products: [
.library(
name: "OctoIO",
type: .dynamic,
targets: ["OctoIO"]
)
],
dependencies: [
.package(url: "https://github.com/apple/swift-log.git", from: "1.0.0"),
],
targets: [
.target(
name: "OctoIO",
dependencies: [
.product(name: "Logging", package: "swift-log"),
],
path: "Sources"
),
]
)
Octo links to the dynamic library created:
// swift-tools-version: 5.7
import PackageDescription
let package = Package(
name: "Octo",
platforms: [.macOS(.v13)],
products: [
.executable(
name: "octo",
targets: ["OctoCLI"]
),
],
dependencies: [
.package(path: "SharedLibraries/OctoIO"),
],
targets: [
.executableTarget(
name: "OctoCLI",
dependencies: [
.product(name: "OctoIO", package: "OctoIO"),
]
),
]
)
OctoIO exports the Logging API:
@_exported import Logging
In Octo, I use OctoIO and use the Logging API
import OctoIO
func run() {
let logger = Logger(label: "MyLogger")
// ...
}
run()
Everything compiles.
When I run the executable however, I get a lot of warnings from ObjC. This is one of them:
objc[69609]: Class _TtC7Logging4Lock is implemented in both /path/to/.build/x86_64-apple-macosx/debug/libOctoIO.dylib (0x10a2fc268) and /path/to/.build/x86_64-apple-macosx/debug/octo (0x108b92030). One of the two will be used. Which one is undefined.
When I inspect both the dynamic library (OctoIO) and the executable (Octo) with objdump -d
, I find the symbol Logging4Lock
is present in both.
How can I convince Swift to not only dynamically link OctoIO, but also its dependencies?