1

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.

1 Answer 1

1

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).

Sign up to request clarification or add additional context in comments.

1 Comment

Quite possibly this is correct. I tried building both for the emulator (i386 build) and the device, it seemed as though both the library and the app were building for the architecture. I deleted the static library project and re-created it from scratch and that fixed the problem so I'm at a loss to say what it actually was.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.