How to specify compatibility version for dylib in iPhone projects? - iphone

I recently added a static library (mobclix) to my iPhone project which required me to set the Base SDK to 3.0. This library is claimed to be compatible with 2.2 and so far it looks like it's true. I set the project's Deployment Target to 2.2. No problems there.
Now, I am also using libxml2 in this same project. Apparently, the libxml2.2.dylib in OS 3.0 is newer than in OS 2.X (version 10 and 9 respectively). However, my code that uses libxml2, was already compatible with the libxml2 version included with OS 2.X. Since I needed to set the Base SDK to 3.0, the "compatibility version" / minimum version requirement / dependency is automatically set to the newer version of libxml2. When I try to run the app in OS 2, I get this runtime error (obviously):
Dyld Error Message:
Library not loaded: /usr/lib/libxml2.2.dylib
Referenced from: /Users/Martijn/Library/Application Support/iPhone Simulator/User/Applications/4D5456DE-F297-4DF4-ACA6-DA8BBBBBA914/Luisterpaal.app/Luisterpaal
Reason: Incompatible library version: Luisterpaal requires version 10.0.0 or later, but libxml2.2.dylib provides version 9.0.0
Is it possible to override the version requirement somewhere?
Or other ideas to solve this issue?

The compatibility version is set according to the version embedded in the dylib of the current SDK during build. I have not found a way to change or override this.
However, in the target in Xcode under the "Link with binary with libraries" branch there is an option to link a dylib "weakly". This skips version checking at the time of loading the dylib (runtime). It's your responsibility then to only make calls to existing functions. Making calls to non-existent functions will crash the application.

Apparently there was a change with SDK 3.0 that broke compatibility with libxml. Apple have posted about it here:
http://developer.apple.com/iphone/library/qa/qa2009/qa1659.html

Related

XCode 14 - Minimum deployment target for SPM package

I am actually compiling for macOS 10.12, as stated. I import the Reachability.swift package, that is compatible down to 10.9. No minimum version is indicated within the Package.swift file. However, I get this error while compiling :
Compiling for macOS 10.12, but module 'Reachability' has a minimum
deployment target of macOS 10.13
It happens since I updated to XCode 14, with version 13, there was no problem.
If I specify the minimum version in the Package.swift of Reachability platforms:[.macOS(.v10_10)],, I clean all the caches, I get the same problem.
I could probably upgrade deployment target to 10.13 (same computer compatibility) or simply include the Reachability.swift file in my code, but I would rather that it works...
[EDIT] Note : other packages, like AppCenter, do not have the same problem… which is weird.
[EDIT 2] With the release of XCode 14.1, the problem remains the same.
Do you have any suggestion ?
I can reproduce your problem: Using AppCenter is OK, but the reachability throws an error.
Here is what I found and maybe this is the root cause:
Make Reachability a local SPM, and modify its swift-tool-version settings and platform settings to align with AppCenter.
Then if you click into the .v10_12 MacOSVersion, you will find os versions lower than 10.13 has all been marked as unsupported
If you head to the built files, test it with otool, you will find the built product's minimum supported version matches with the above description:
So even if you specify the minimum support version to 10.12, the build tools will still target 10.13.
If you check LC_MIN_VERSION_MACOSX on AppCenter. It is also targeting 10.13 instead of 10.12 in its package.swift file.
But why Xcode accepts AppCenter and raise an error for Reachability?
Check the build log below. You will find it in the emitting module stage, the build system is using swift-frontend to embed those 3rd party dependencies. So I guess since the AppCenter is written in objective C.
The checking minimum os version behavior of swift-frontend is different between OC Dependency "AppCenter" and Swift Dependency "Reachability."

Swift Version Conflict: this SDK is not supported by the compiler - using BUILD_LIBRARY_FOR_DISTRIBUTION setting. What could be the issue?

I'm building a Swift static library with:
Xcode 13.2 (Swift compiler 5.5.2)
iOS Deployment target 12.0
Build library for distribution YES
Skip install NO
Swift language version 5 and tried with 4.2
Dependency managed with CocoaPods:
Japx 3.0.0
Alamofire 5.2.2
RxSwift
When I try to add it to an iOS project with this setup:
Xcode 13.3 (Swift compiler 5.6)
iOS Deployment target 12.0
Swift language version 5 and tried with 4.2
and build I get this error:
Failed to build module 'LibraryX'; this SDK is not supported by the compiler (the SDK is built with 'Apple Swift version 5.5.2 effective-4.2 (swiftlang-1300.0.47.5 clang-1300.0.29.30)', while this compiler is 'Apple Swift version 5.6 effective-4.2 (swiftlang-5.6.0.323.62 clang-1316.0.20.8)'). Please select a toolchain which matches the SDK.
These are the headers in the .swiftinterface
// swift-interface-format-version: 1.0
// swift-compiler-version: Apple Swift version 5.5.2 effective-4.2 (swiftlang-1300.0.47.5 clang-1300.0.29.30)
// swift-module-flags: -target arm64-apple-ios12.0 -enable-objc-interop -enable-library-evolution -swift-version 4.2 -enforce-exclusivity=checked -Onone -module-name LibraryX
Obviously if I build the project with the same compiler version or building the library with the iOS project everything works fine. But the purpose here is to release a precompiled library and not its source code.
Every time that I lookup this error online I've found "You have to set Build library for distribution to Yes"
I tried to add the source code of the static library to a new Framework project, but I get the same result.
I also had this error, in my case it was unable to import a sub-dependency of my XCFramework during reading .swiftinterface file, however was showing this absolutely misleading error.
After repeatedly cleaning up DerivedData and trying different Xcode versions (13.0, 13.4.1) I've seen 2 errors: "this SDK is not supported by the compiler", and "No module named 'AnotherLib'" which was an incorrectly specified dependency inside of my Swift Package.
So, maybe only first part of the message is correct "Failed to build module 'LibraryX'", but the reason is something else, NOT the difference in compiler versions.

Swift Version Conflict: this SDK is not supported by the compiler, Please select a toolchain which matches the SDK

I'm using xCode 13.1 with macOS 12.0.1 Monterey. I added KingFisher and removed it from my pod. but my project is not built anymore. I got this error for one of my local SDKs:
Failed to build module 'CbSdk';
this SDK is not supported by the compiler (the SDK is built with 'Apple Swift version 5.4
(swiftlang-1205.0.26.9 clang-1205.0.19.55)', while this compiler is 'Apple Swift version 5.5.1
(swiftlang-1300.0.31.4 clang-1300.0.29.6)'). Please select a toolchain which matches the SDK.
What I've done but didn't work:
pod deintegrate and pod install.
restart xCode with clearing cache and DerivedData.
checkout old branch and commit that worked before.
moving code to another macBook that worked before.
download, install and select toolchain 5.4 (odd errors appeared -> )
changing swift compiler language of my target and project to swift 4 (It says you are using swift 5.5.1 again!)
note that I didn't update xcode or swift!
Taken from this Twitter thread.
You need to set the BUILD_LIBRARY_FOR_DISTRIBUTION build setting on the framework target
https://www.swift.org/blog/library-evolution/
https://developer.apple.com/videos/play/wwdc2019/416/
I fetch the same problem when I try to update a library. My Xcode version was 13.2 with the swift version5.5.2. But the library I want to update required a swift version of 5.7.0. Using toolchains in Xcode might be the solution but I decided to update the Xcode version with the latest.
I update my Xcode to the latest version 14.1 and the issue is resolved. Automatically the swift version is found on the latest Xcode.

Swift Package Manager - How to `Always Embed Swift Standard Libraries`?

We have CLI tool written in Swift for common usage (Android and iOS developers) on macOS.
Android developers without Xcode installation get the following error:
dyld: Library not loaded: #rpath/libswiftCore.dylib
Referenced from: ~/git/myClITool/macosBin Reason: image not found
Abort trap: 6
We found that enabling Always Embed Swift Standard Libraries in Xcode would most likely help, but this CLI tool is exported with SPM, ignoring all Xcode settings.
How can I achieve this build behaviour using SPM only?
Found the following commandline argument: --static-swift-stdlib
Example usage:
swift build --static-swift-stdlib -c release
This would have produced the output we were looking for. Unfortunately since Swift 5, this argument no longer works for any platforms.
When used, SPM throws the following warning:
warning: Swift compiler no longer supports statically linking the
Swift libraries. They're included in the OS by default starting with
macOS Mojave 10.14.4 beta 3. For macOS Mojave 10.14.3 and earlier,
there's an optional Swift library package that can be downloaded from
"More Downloads" for Apple Developers at
https://developer.apple.com/download/more/
Related Swift bugticket: https://bugs.swift.org/browse/SR-648

Framework issue - Module file was created by an older version of the compiler

I'm using
newest OpenXSDKframework (debug)
included in embedded Binaries
Build Settings: Embedded Content Contains Swift Code YES
Other linker -Objc
XCode 7.31
swift
when import OpenXSDKCore
this error is showing
.../ViewController/OpenXBannerViewController.swift:11:8: Module file
was created by an older version of the compiler;
rebuild 'OpenXSDKCore' and try again:
.../OpenXSDKCore.framework/Modules/OpenXSDKCore.swiftmodule/i386.swiftmodule
is this related to the Framework producing Company ?
what should i do - to fix that error?
thanks
That error will occur if the compiled framework (binary) was compiled using earlier version of compiler and in the most of the iOS cases it means that the binary was compiled using some earlier versions of Xcode.
Most probably, your OpenXSDKCore was not built using Xcode 7.3 that you use. The best course of action would be downloading the framework source code and compiling it by yourself.
If you don't have that option you can only wait or downgrade to earlier Xcode version.