SPM. How to set current_version and compatibility_version for my dynamic library

I can set current_version and compatibility_version when using XCode but don't know how to do that using Swift Package Manager (SPM).

In XCode compilation log I have seen:

-Xlinker -no_deduplicate -fobjc-arc -fobjc-link-runtime -compatibility_version 1.0 -current_version 1.0.1

But in SPM when I add any combination of "-Xlinker -compatibility_version 1.0 -current_version 1.0.1" always got an error

swift build -v -Xlinker -compatibility_version 1.0 -Xlinker -current_version 1.0.1
error: unexpected argument 1.0; use --help to list available arguments

swift build -v -Xlinker -compatibility_version\ 1.0 -Xlinker -current_version\ 1.0.1
ld: unknown option: -compatibility_version 1.0

It looks like SPM is not ready for additional value 1.0 after -compatibility_version.

I believe SPM requires that you repeat the -Xlinker flag before each argument, so the invocation should be:

swift build -v \
  -Xlinker -compatibility_version -Xlinker 1.0 \
  -Xlinker -current_version -Xlinker 1.0.1

I don't know if passing these flags will solve your problem, but this should pass them to the linker, at least.

1 Like

Many thanks. It's work!

1 Like

I can set current_version and compatibility_version when using

FYI, these constructs are effectively deprecated. They might have made sense back at the dawn of Mach-O but they don’t make a lot of sense given the way we ship software for Apple platforms today. Libraries typically evolve in a binary compatible fashion. In extreme cases, where you want to completely break binary compatibility, you would simply change the library’s name.

Share and Enjoy

Quinn “The Eskimo!” @ DTS @ Apple

Hello, I face a problem with dependency A that require a dependency B to have a version set:

Reason: Incompatible library version: XXXX requires version 1.0.0 or later, but AFNetworking provides version 0.0.0

I tried to set the current_version of the AFNetworking to solve this issue. As the build is triggered directly by Xcode, I can't add these options as-is. I found in the PackageDescription that I can add:

linkerSettings: [
    .unsafeFlags(["-current_version 1.0.0"])

But now, I can't add this package as dependency anymore because this unsafe flag.
I don't know what to do now...

Terms of Service

Privacy Policy

Cookie Policy