Search code examples
objective-ciosxcode4linker

Xcode creating & using static libraries with linking errors


I'm attempting to use the EGOPhotoViewer as a static library in my project, such that I don't need to include all their source code directly in my project.

I've forked the project and created a cocoa touch static library to generate libEGOPhoto.a

Modifications have been made to the demo project to take advantage of the static library instead of source code, so I've removed the library classes and added the static library as a Framework. One other stack answer suggested adding it as a compiled source but that didn't work either.

The error that I get is related to linking and is as follows:

ld: warning: ignoring file /Users/pbrooks/Library/Developer/Xcode/DerivedData/EGOPhotoViewer-chniasxgqzkdbwhjedastrvwlmek/Build/Products/Debug-iphoneos/libEGOPhotoViewer.a, file was built for archive which is not the architecture being linked (i386)

Undefined symbols for architecture i386:
"_OBJC_CLASS_$_EGOPhotoViewController", referenced from: objc-class-ref in RootViewController.o objc-class-ref in DetailViewController.o objc-class-ref in RootViewController_iPhone.o ld: symbol(s) not found for architecture i386

clang: error: linker command failed with exit code 1 (use -v to see invocation)

Any tips on getting this linking correct?


Solution

  • You're trying to compile for simulator (which requires an i386 architecture for the intel processors in your mac). Your library is probably compiled for ARMv6/ARMv7 architecture used for iOS devices. You might be able to just run it on the device as it is. If you also want to run on simulator, you should make different libs and link based on whether you are targetting an iOS device or the simulator (or make a universal lib which contains both architectures).