Linking a static or dynamic library to a project in a workspace?

I’ve done this before, several years ago with Xcode 5 or 6. Now using Xcode 8 or 9, I seem to be missing someting.
No matter what I’v done, when I try to build and link my project, I get the Linker message:

Undefined symbols for architecture arm64:
OBJC_CLASS$_MyClass”, referenced from:
objc-class-ref in ViewController.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

I’m writing in objective-C for this project if that matters (I don’t think it does)

My question is what did I forget?

What I did –

  1. Create a project for my framework and static library
    a) create the project for a cocoa-touch framework - let’s call it mySDK which creates mySDK.framework
    b) Add a target for a cocoa-touch static library - let’s call it SDK which creates libSDK.a
    c) optionally build both targets – they build fine
    d) close the project

  2. Create a project for my application - myApp - then close the project

  3. Create a workspace - myWorkspace – and open the workspace

  4. Drag both project files from #1 mySDK and #2 myApp into the workspace

  5. Build the framework and static library (both build and create the targets successfully)

  6. Add the static library to myApp
    6a) Select myApp and go to build phases
    6b) Open Link Binary with Libraries
    6c) Drag from the library build products libSDK.a into the link binaries pane, set to “Required”
    The library now appears in the Frameworks group-area in the myApp

  7. Select the myApp project and go to build-settings
    7a) Add to Header Search Paths = “$(SRCROOT)/…/mySDK/mySDK”
    This resolves compile errors in finding the headers

Now I ask, why do I need to do anything else, shouldn’t Xcode figure the rest out?

Various solutions or tutorials I’ve reviewed suggest adding:

A) Other Linking Flags = -ObjC
B) Library Search Paths = $(BUILT_PRODUCTS_DIR)
C) Library Search Paths = “$(SRCROOT)/…/mySDK”

D) Changing Skip Install from YES to NO
E) Installation Build Product Location = $(BUILT_PRODUCTS_DIR)

Once I added the library to myApp I see that the Frameworks/libSDK.a file changes from red to black when I build the library so something in the workspace/project knows I built the library and it sees it.

So why when I try build myApp, do I still see the liner error:

Undefined symbols for architecture arm64:
OBJC_CLASS$_MyClass”, referenced from:
objc-class-ref in ViewController.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Nothing I have done seems to clear that error. I am pulling my hair out trying to find a solution.

I have also checked that it is building all the appropriate architectures, confirmed it using ‘lipo -info’

Xcode obviously knows about the library, why isn’t it linking?

This topic was automatically closed after 166 days. New replies are no longer allowed.