-ObjC flag causes duplicate symbols with Swift Packages

I have a similar problem that described in my post here: Direct & indirect static libs dependencies with SPM + Xcode

I don't think this is related to the -ObjC flag. Looking at the github sample project, the problem is that Xcode will link the Package static lib into the static lib target, and then it will do it again on the app, leading to duplicate symbols. We need finer control in Xcode: being able to declare a dependency to another static lib with or without linking it. (without linking means that some other target will have to do it manually)

In your case, I see 2 possible workarounds. The best one, since your Package is inside the static lib Xcode project, you can declare a dependency through Xcode Build Phases pane, and remove the linked libraries.

For the other case when the package is not part of the Xcode project, but just resides in the same Xcode workspace (my case), I do have a workaround too: have the package create that same lib as a dynamic one, and make the static lib target link against this one (hint: it won't actually link against it, since it's dynamic). The main app target can then just link against the static one, as it should be.

    .library(
        name: "Package",
        type: .static,
        targets: ["Package"]),
    .library(
        name: "Package-stub",
        type: .dynamic,
        targets: ["Package"]),

I sure hope this gets addressed, as this is a common use case. The scenario to focus on is a number of dependent static libs, either defined through Xcode or SPM, and an app that link those both directly (some) and indirectly (some other ones). FYI, I also went through a related problem: the module map of inner libs wouldn't be correctly exposed to (outer) targets that would link indirectly.

1 Like