Built for macOS not UIKit for Mac

Hi


I've started looking at running my iPad app in macOS 10.15 using Xcode 11. I've run through the steps to add Mac support but when I build it complains that some of the libraries I use at link time are compiled for macOS and not "UIKit for Mac". Surely they are both x64 architecture so I'm slightly confused. I can't find any documentation about this - does anyone have any idea on how I would rebuild these libraries so that they are supported?


Thanks,

Mike.

Accepted Reply

Libraries coming into the UIKit for Mac environment need to be compiled for the iOS platform, not the macOS platform. You may need to alter your Base SDK setting to reflect this. Some other helpful notes:

  • Ensure that the VALID_ARCHS and ARCHS settings are their defaults and not overridden. Overriding these settings can prevent the build from selecting the right architecture for your build.
  • Ensure Perform Single Object Pre-Link is the default value of No (GENERATE_MASTER_OBJECT_FILE is the raw setting name)


When analyzing build settings, I like to use the All | Levels view in Xcode, in order to see a grid of levels where a setting is located, annotated with a green box around the level where the setting is overridden. When I say let these settings be their default value, I mean that the green highlight should be on the Default column in this view and not any other level unless you have a clear reason for overriding any of these.


If you are looking at this grid for a specific target, you can clear a setting at this level by selecting the setting row and pressing the Delete key. If you need to clear a setting at the project level, you should select the project instead of a specific target in the list on the left side of the setting grid, and clear the overridden setting from there.

Replies

You likely did not remove the previous library from your build. Make sure it's cleared from Frameworks in the General tab as well as the Build Phase - Link with Binary Libraries.


I can assure you this will compile openssl for UIKitForMac.

@edford

Hi can you help me this error? I managed to build xcframework file ‘libjre_emul.xcframework’. My static library project includes ‘libjre_emul.xcframework’. Building the project with iOS device or simulator succeeds but for mac app I get a build error.


“error: Unable to find a suitable library in the XCFramework ‘libjre_emul.xcframework’ (in target ‘AirNote’)“.


In ‘libjre_emul.xcframework’ I included binary built for mac too.

As Xcode 11 is still in beta, you should make a note of the exact command line invocations you made, and open a bug report with those commands, the built xcframework you created, and how you are using the xcframework in a client application.

Hi @edford, is there a way to keep GENERATE_MASTER_OBJECT_FILE = YES for our static lib and build the project for UIKitForMac?

speaking fo xcodebuild: has anyone figured out yet how to build (a library or app) for the UIKit for Mac destination using xcodebuild? `-sdk` onkly lets me distinguish between "iphoneos" and "iphonesimulator" 😟.

My previous posted advice was to help people get started with Beta 1, as I talked to developers not able to build with that setting in the WWDC labs. In those cases, they also didn't have a real need for that setting to be enabled at all. If you have a real need for that build option to be available with UIKIt for Mac and it doesn't currently work for you with Beta 3, please open a feedback item.

I have the same issue while creating xcframework for my framework to support sdks - iphoneos , iphonesimulator and macos. I tried to do the same on macos catalina beta with xcode 11 beta 5.
I was able to create archive for sdks - iphoneos and iphoneSimulator but I am facing issues while using -sdk macos.
I getting error :


.... error: 'UIKit/UIKit.h' file not found

#import <UIKit/UIKit.h>

^

<unknown>:0: error: could not build Objective-C module 'MyFramework'


** ARCHIVE FAILED **


I searched and found that UIKit framework is only available for iOS and not for macos.
So, not sure how to achive this.
Really appreciate if someone can help here.


I tried adding the CFLAGS as you mentioned but it still failed.


The changes I have done is -

* added the CFLAGS=-target x86_64-apple-ios13.0-macabi

* I ran against the sdk - iPhoneSimulator

But it failed with the below mentioned error no matter which sdk I use :


ld: building for UIKitForMac, but linking in .tbd file (/Applications/Xcode11-beta3.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.0.sdk/usr/lib/libSystem.tbd) built for iOS Simulator, file '/Applications/Xcode11-beta3.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.0.sdk/usr/lib/libSystem.tbd' for architecture x86_64


clang: error: linker command failed with exit code 1



And the similar error I get if i run it against iPhoneOS sdk.

I believe somewhere I have to specify the linking option but not sure where.


Can you please suggest what is wrong here? I am stuck at this place.



Thanks.

Hi.


For Xcode IDE GUI, I can successfully build the macOS Catalyst framework. The build settings works well.


But my use case is : How can I use `xcodebuild` command line, to do the same thing to build macOS Catalyst framwork ?


I've tried both of them:


- sdk: iphoenos, iphonesimulator, macosx (note there are no any oher SDK like maccatalyst)

- destination: 'platform=macOS,arch=x86_64,variant=Mac Catalyst' there is one interesting, but does not solve the problem

- CFLAGS="-target x86_64-apple-ios13.0-macabi", whether added or not does not cause anything different on product


Because for us, we need to combine all the individual framework into a XCFramework and automate our build pipeline. Build on Xcode GUI, drag and drop then run script, this is not way we want to do. Because it need `people manual do things`.


Hope for reply.

Hello! Did you manage to find a solution from building from cmd line using xcodebuild? If not, what worked for us was: xcodebuild -verbose clean build -project testprj.xcodeproj -scheme "testprj" -configuration "Debug" -destination 'platform=macOS,arch=x86_64,variant=Mac Catalyst' SKIP_INSTALL=NO Very important is to set the " -scheme" flag.

Were you able to solve this issue?

I'm now using makefile to generate FFMpeg libraries, everything builds correctly, but i have a problem during building xcframework.

Here are my compiler and linker flags.


CFLAGS="$CFLAGS -target x86_64-apple-ios13.0-macabi \
  -isysroot $xcode_path/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk \
  -isystem $xcode_path/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/iOSSupport/usr/include \
  -iframework $xcode_path/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/iOSSupport/System/Library/Frameworks"


  LDFLAGS="$LDFLAGS -target x86_64-apple-ios13.0-macabi \
  -isysroot $xcode_path/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk \
  -L$xcode_path/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/iOSSupport/usr/lib \
  -L$xcode_path/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/maccatalyst \
  -iframework $xcode_path/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/iOSSupport/System/Library/Frameworks"

I tried to use built library and also I tried to use object files to glue them into library with libtool.


libtool -static -arch_only $ARCHS -D \
  -syslibroot $xcode_path/MacOSX.platform/Developer/SDKs/MacOSX.sdk \
  -L$xcode_path/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/iOSSupport/usr/lib \
  -L$xcode_path/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/maccatalyst \
  $object_files \
  -o "$TMP_FOLDER/$FRAMEWORK_NAME"



Then I do following to create XCFramework from libraries:


xcodebuild -create-xcframework \
  -library "arm64/$LIB_NAME" \
  -library "x86_64/$LIB_NAME" \
  -headers "include" \
  -output "$XCFRAMEWORK"



When I try to create XCFramework with only iOS arm64 slice, it succeeds.

If I use mac-catalyst x86_64 slice, it fails with following error


error: unable to find any specific architecture information in the binary at 'foo/bar/x86_64/libavcodec.a'

Key @Skaro, I've opened a PR on the OpenSSL-for-iPhone repo adding support to Catalyst.


You can use y code by running the following on your terminal:

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

I've tested this code in a real project and it worked fine. Please let me know if it works for you too.

BTW, those warnings (and I'm dealing with them too in an open source lib) are now hard errors in Xcode 11.4-beta. FYI.

Did you ever resolve the issue:

error: unable to find any specific architecture information in the binary at 'foo/bar/x86_64/libavcodec.a'


I'm running into the same error trying to build an xcframework for FFmpeg.


EDIT:


Nevermind, I see that you figured out the cause: https://github.com/kewlbear/FFmpeg-iOS-build-script/pull/147#issue-325840617


"x86_64 binaries are built without ASM support, since ASM for x86_64 is actually x86 and that confuses

xcodebuild -create-xcframework
"


For anyone else running into this issue with FFmpeg, you need to add "--disable-asm" to the configure flags.