Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 441
marcelosalloum Avatar asked Jun 06 '19 14:06

marcelosalloum


2 Answers

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"
like image 101
marcelosalloum Avatar answered Nov 09 '22 23:11

marcelosalloum


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
like image 1
Tom Vos Avatar answered Nov 09 '22 21:11

Tom Vos