Reputation: 45210
I am developing an open-source iOS static library with a demo project. I created my "library" xcodeproj, created a class DKNavigationBar
, included it where I had to include it. Then I created a "demo" xcodeproj and dragged "library" xcodeproj into it. I included my static library in "Target Dependencies" section and imported my library in the pch file using #import <MyLibrary/MyLibrary.h>
. I built the demo project and there was no errors at all. Then, in my DKDAppDelegate.m
I called [DKNavigationBar class]
- LLDB gave me no error. Then I built my project and boom:
Undefined symbols for architecture i386:
"_OBJC_CLASS_$_DKNavigationBar", referenced from:
objc-class-ref in DKDAppDelegate.o
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
At the first glance, it seems like a normal mistake: "Oh, I forgot to add my source file to the 'compile sources' build phase". But when I looked deeper and deeper I realized that everything is set up correctly. After some research I realized that symbol definition is present in my .a
file and the static library is built for my architecture:
$ cd /path/to/derived/data/product/folder
$ lipo -info libMyLibrary.a
input file libMyLibrary.a is not a fat file
Non-fat file: libMyLibrary.a is architecture: i386
$ otool -MVv libMyLibrary.a
Archive : libMyLibrary.a
libMyLibrary.a(DKNavigationBar.o):
Module table (0 entries)
$ nm libMyLibrary.a
libMyLibrary.a(DKNavigationBar.o):
00000074 S _OBJC_CLASS_$_DKNavigationBar
U _OBJC_CLASS_$_UINavigationBar
00000060 S _OBJC_METACLASS_$_DKNavigationBar
U _OBJC_METACLASS_$_NSObject
U _OBJC_METACLASS_$_UINavigationBar
U __objc_empty_cache
U __objc_empty_vtable
00000038 s l_OBJC_CLASS_RO_$_DKNavigationBar
00000010 s l_OBJC_METACLASS_RO_$_DKNavigationBar
Now I have no idea what's going wrong. Any help would be appreciated.
TL;DR
undefined symbols for architecture
clang error pops upUpvotes: 1
Views: 2695
Reputation: 1154
Add the library under "Link Binary With Libraries" in build phases.
Upvotes: 4