Typically, this plugin offers two ways of handling linking libraries/frameworks of a package.
- Based on xcconfig settings
- Xcode's default linking
We rely on xcconfig settings to provide all linker flags for a package's libraries/frameworks. This aligns with how CocoaPods is currently linking pod targets. This strategy is going to be how the plugin handles linking in the long term.
With this strategy, a product of a package is added to the "Link Binary With Libraries" section of a dependent target.
To opt in for this strategy, use the option use_default_xcode_linking
(nested inside the :linking
option) as follows:
spm_pkg "Foo",
:path => "url/to/package",
:linking => {
:use_default_xcode_linking => true # <-- HERE
}
While letting Xcode handles the linking is reliable, we might end up with some issues.
We often encounter the Duplicate symbols
error during linking phases.
This happens when the -ObjC
linker flag is present (related: here). This seems to be an issue with the new linker (since Xcode 15).
A workaround for this issue is to switch to the old linker by adding the -ld_classic
linker flag.
Use the :linker_flags
option (nested inside the :linking
option) for this purpose.
spm_pkg "Foo",
:path => "url/to/package",
:linking => {
:use_default_xcode_linking => true,
:linker_flags => ["-ld_classic"] # <-- HERE
}