Linker error with XCTest.framework

I have my macOS app compiling and running under Big Sur and Xcode 12, however when I attempt to run the unit tests, I get the following two linker warnings.

Code Block
ld: warning: dylib (/Applications/Xcode12-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Frameworks/XCTest.framework/XCTest) was built for newer macOS version (10.15) than being linked (10.14.4)
ld: warning: dylib (/Applications/Xcode12-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/lib/libXCTestSwiftSupport.dylib) was built for newer macOS version (10.15) than being linked (10.14.4)


Our deployment target is indeed 10.14.4. I've combed through the release notes for Xcode12 looking for some mention of XCTest only working on 10.15 and higher, but can't seem to find anything.

Can anyone offer any advice as to whether this is just a temporary problem with the beta, or if it's no longer possible to have a deployment target <10.15 with unit tests?

For the record, the unit tests end up running just fine, but I have this linker warning for every test target.
Thanks!

Accepted Reply

XCTest framework is not intended to back-deploy to versions of macOS that are older than the minimum macOS version supported by Xcode. I believe that the reason you are seeing this warning is because the MACOSX_DEPLOYMENT_TARGET setting for your test target is set to 10.14.4. It's fine to have your application target's deployment target set to 10.14.4 since that's the minimum OS version you are supporting with your app, but you should have your test target's minimum deployment target be set to 10.15 or higher.

Replies

XCTest framework is not intended to back-deploy to versions of macOS that are older than the minimum macOS version supported by Xcode. I believe that the reason you are seeing this warning is because the MACOSX_DEPLOYMENT_TARGET setting for your test target is set to 10.14.4. It's fine to have your application target's deployment target set to 10.14.4 since that's the minimum OS version you are supporting with your app, but you should have your test target's minimum deployment target be set to 10.15 or higher.
I've noticed this as well and I don't think I've ever seen the issue before Xcode 12. The workaround suggested to ensure the test target uses a modern deployment target works well if the test target injects into a separate application target for testing, but when the test target itself compiles and links source files to be tested directly, it imposes the modern deployment target to the source files, which creates a different test environment than desired.

I couldn't easily find an ld option to suppress the warnings about differing deployment target.
I believe the warning is related to this paragraph in the Xcode 11.4 Release Notes:

"Xcode now validates the deployment target of test bundle targets, and skips running any tests that are incompatible with the selected run destination. Some targets may require a change to their minimum deployment target build setting to continue to run on older run destinations. (39775813)"
https://developer.apple.com/documentation/xcode-release-notes/xcode-11_4-release-notes

As soon as I changed the Deployment Target on the *XCode project* file, the warning disappeared.