I have no cat
I have no cat

Reputation: 236

Linker cannot find functions or classes in static library (Objective C)

I have an XCode 4.2 workspace containing a Cocos Touch Static Library (mixed Objective C, Objective C++ and C++) and a cocos2d iOS app. The static library and the iOS app are both siblings.

The problem is the app's linker fails when trying to link to the functions and classes in the static library. The app does have the static library set with "Link Binary With Libraries". It is as though the functions and classes in the static lib are either not being exported or not being looked for by the app.

For example I created a function int foo() { return 42; } and placed it in the library, then called it from main.m in the app.

The error looks like this:

Undefined symbols for architecture armv7:
  "_OBJC_CLASS_$_RootViewController", referenced from:
    objc-class-ref in AppDelegate.o
  "_foo", referenced from:
    _main in main-972D78D1B1575F1.o
  "_OBJC_CLASS_$_CCDirector", referenced from:
    objc-class-ref in AppDelegate.o
    objc-class-ref in libCocos2DBase.a(BaseScene.o)
    objc-class-ref in libCocos2DBase.a(Director.o)
  "_OBJC_CLASS_$_CCLayer", referenced from:
    _OBJC_CLASS_$_FoundationLayer in libCocos2DBase.a(BaseScene.o)
  "_OBJC_METACLASS_$_CCLayer", referenced from:
    _OBJC_METACLASS_$_FoundationLayer in libCocos2DBase.a(BaseScene.o)
  "_OBJC_CLASS_$_CCTexture2D", referenced from:
    objc-class-ref in AppDelegate.o
  "_OBJC_CLASS_$_EAGLView", referenced from:
    objc-class-ref in AppDelegate.o
  "_OBJC_CLASS_$_CCScene", referenced from:
    objc-class-ref in libCocos2DBase.a(BaseScene.o)
ld: symbol(s) not found for architecture armv7
collect2: ld returned 1 exit status

Thank you so much for anybody that can help, I'm new to XCode and have spent a lot of time looking for a solution.

Upvotes: 1

Views: 3088

Answers (1)

mipadi
mipadi

Reputation: 411242

It looks like your static library was not compiled for the armv7 architecture, whereas the app using it is, so it can't find the proper symbols. Try compiling the static library for armv7 (or if you don't have the source, see if you can get the developer to compile it for armv7).

Upvotes: 1

Related Questions