Apple Watch app: libobjc.A.dylib not found

I am trying to add an Apple Watch companion app to my iPhone app. I have no experience with Apple Watch at all, so I followed the Apple instructions as described on https://developer.apple.com/tutorials/swiftui/creating-a-watchos-app I followed that instruction to the letter, and did not add anything to it, and now have two targets in the project: the original iPhone target, and the Apple Watch target.

When I try to build the Watch app, I get the following linker error:

error: Build input file cannot be found: '/usr/lib/libobjc.A.dylib'. Did you forget to declare this file as an output of a script phase or custom build rule which produces it? 

The linker command has the following argument on it:

-weak_library /usr/lib/libobjc.A.dylib

The "Link binary with libraries" option of the "Build Phases" of the Apple Watch target does not have any libraries specified.

Does anybody know what the libobjc library is, and what it is used for? Where is this linker flag configured? How can I make this work?

EDIT: The -weak_library /usr/lib/libobjc.A.dylib is configured in the Project Build Settings, "Other Linker Flags". It seems to be a basic necessity that was already there before I added the Watch target. When I remove it, I get "Undefined symbol: _main" errors. So it seems to be something fundamental that is required. The question is now why it is not found by the linker.

If it matters, the iPhone app has always been Objective-C, but I'd like to start with Swift for the Apple Watch app, so have chosen to create that as a Swift app.

Replies

The -weak_library /usr/lib/libobjc.A.dylib is configured in the Project Build Settings, "Other Linker Flags".

This is a very weird build setting to have configured.

When I remove it, I get Undefined symbol: _main errors.

That’s a very weird symptom to get when you remove it.

There’s something misconfigured about your main project which is why you’re having problems with adding Apple Watch support. I recommend that you remove this build setting first, fix that problem, and then come back to your original quest.

As to how you do that, try creating a new iOS app from the built-in template and look at how it’s configured. It will have a main.m file that provides the main function that the linker is looking for.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"