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
Xcode

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

Terms of Service

Privacy Policy

Cookie Policy