Xcode 11 not recognizing static library's architecture: MacCatalyst (aka UIKitForMac)
Asked Answered
F

2

6

After getting excited about 2019's WWDC announcements, I tried compiling my existing iOS app against the MacOS using Xcode 11.0 beta. Unfortunately, it didn't go as expected.

Xcode says my static library is built for < unknown > architecture:

Building for UIKit for Mac, but the linked library 'libssl.a' was built for < unknown >. You may need to restrict the platforms for which this library should be linked in the target editor.

Xcode screenshot

But when I check my static libs, I can see they do contain the desired architecture x86_64: enter image description here

I believe this issue may be related to an Xcode Beta bug. Does anyone have thoughts on this?

Friendship answered 6/6, 2019 at 14:44 Comment(2)
“Xcode says my static library is built for < unknown > architecture“ No it doesn’t. It says platform. And it says you have too many, not too few.Bartholomeo
There is a possible solution here: forums.developer.apple.com/thread/117346. edford, software engineer from apple says: Libraries built for the iOS simulator with previous versions of Xcode need to be rebuilt with Xcode 11 for the Project Catalyst environment specifically for the Mac -- there are differences in the compiled product, and a build for the iOS simulator is not sufficient.Friendship
F
8

One-line fix:

git clone [email protected]:marcelosalloum/OpenSSL-for-iPhone.git --branch feature/mac-catalyst && \
cd OpenSSL-for-iPhone && \
./build-libssl.sh --archs="MacOSX_x86_64 i386 arm64 armv7s armv7"

Explanation:

According to edford, Apple's software engineer, we need to build our binaries for the iOS platform, targeting MacOSX and use the CFLAG -target x86_64-apple-ios13.0-macabi. There is a very enlightening discussion here: https://forums.developer.apple.com/message/362577.

I've forked OpenSSL-for-iPhone here and implemented MacCatalyst support in the branch feature/mac-catalyst.

You can build it for MacCatalyst either by specifying archs or targets:

Option --archs, for OpenSSL <= 1.0.2:

git clone [email protected]:marcelosalloum/OpenSSL-for-iPhone.git --branch feature/mac-catalyst && \
cd OpenSSL-for-iPhone && \
./build-libssl.sh --archs="MacOSX_x86_64 i386 arm64 armv7s armv7"  --version="1.0.2l"

Option --targets for OpenSSL >= 1.1.0

git clone [email protected]:marcelosalloum/OpenSSL-for-iPhone.git --branch feature/mac-catalyst && \
cd OpenSSL-for-iPhone && \
./build-libssl.sh --targets="ios-sim-cross-i386 ios64-cross-arm64 ios-cross-armv7s ios-cross-armv7 mac-catalyst-x86_64" --version="1.1.0"
Friendship answered 2/7, 2019 at 21:23 Comment(7)
Would you be able to share your OpenSSL library that's built for UIKitForMac? Having trouble building it on my machine.Kalong
Hey @bmueller, I've updated the answer above. You should be able to rebuild OpenSSL with MacCatalyst support by calling: bash git clone [email protected]:marcelosalloum/OpenSSL-for-iPhone.git --branch feature/mac-catalyst && cd OpenSSL-for-iPhone && ./build-libssl.sh --archs="MacOSX_x86_64 i386 arm64 armv7s armv7" Friendship
Thanks! The script works well with version 1.0.2l. For some reason, it was failing for other versions of Open SSL.Bode
@Friendship I first tried version 1.0.1e and it kept failing. That gave me a good reason to upgrade to a new version. Thanks again. You saved me a lot of time.Bode
@Friendship It fails searching files in "iPhoneSimulator13.2-x86_64.sdk", which now are in "MacOSX10.15-x86_64.sdk". Did not check code but assume this happens when lipoa fat lib. cp -r "MacOSX10.15-x86_64.sdk" "iPhoneSimulator13.2-x86_64.sdk" fixes the issue.Fishbein
@shallowThought: How do I reproduce this error? It works for me when I run the command option ./build-libssl.sh --archs="MacOSX_x86_64 i386 arm64 armv7s armv7" --version="1.0.2l" above. If you share the exact command you've used I can take a look. Please remember that a lipo file can hold only a single binary per architecture, so if you're adding both MacOSX_x86_64 and x86_64 it won't work.Friendship
@marcelosalloum: this is the command, which we are running from a Xcode build script: ./build-libssl.sh --targets="ios-sim-cross-i386 ios64-cross-arm64 ios-cross-armv7s ios-cross-armv7 mac-catalyst-x86_64" --version="1.1.0". I do not mess with lipo, I just guessed that is what's happening in your code. Trying to create a fat lib containing a slice from "iPhoneSimulator13.2-x86_64.sdk", which does not exist. It was only a guess, ignore that part.Fishbein
L
1

All the above solutions didn't work for me, so I went on and tried to fix it for my system running Mac OSX 10.15.4.

In my case this is where the above solutions stopped working for me:

no such sysroot directory: '/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.4.sdk' [-Wmissing-sysroot]

I read through the build-libssl.sh file noticed that the sdk version was taken by the script using the code:

xcrun -sdk macosx --show-sdk-version

which on my system does return:

10.15.4

Using finder an navigating to the location:

'/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/

did show me there was indeed no MacOSX10.15.4.sdk. There was however a MacOSX10.14.sdk. I did use this knowledge to come up with the following solution:

OpenSSL version <= 1.0 (1.0.2l)

versions <= 1.0 should only use --arch, not --target !

git clone [email protected]:marcelosalloum/OpenSSL-for-iPhone.git --branch feature/mac-catalyst && \
cd OpenSSL-for-iPhone && \
./build-libssl.sh --arch="MacOSX_x86_64 i386 arm64 armv7s armv7 tv_x86_64 tv_arm64" --macosx-sdk=10.15 --version="1.0.2l"

OpenSSL version >= 1.1 (1.1.0) currently not functional

versions >= 1.1 should only use --target, not --arch !

git clone [email protected]:marcelosalloum/OpenSSL-for-iPhone.git --branch feature/mac-catalyst && \
cd OpenSSL-for-iPhone && \
./build-libssl.sh --targets="mac-catalyst-x86_64 ios-sim-cross-i386 ios64-cross-arm64 ios-cross-armv7s ios-cross-armv7 tvos-sim-cross-x86_64 tvos64-cross-arm64" --macosx-sdk=10.15 --version="1.1.0" -v
Lathy answered 16/4, 2020 at 20:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.