I am attempting to use a static library (.a) for which I also have the header files (no .m files), but when I add the library to my target (without even referencing/importing the library in my project code), I receive the Undefined symbols for architecture armv7
linking error at compile time. The linker is complaining about classes that supposedly no longer exist in the newest version of the library, and may be using cached data? That suspicion could be supported by the finding that if I create a blank project and add the library in the exact same way as I added it to my project, the new project compiles without issue. But on another note, when I grep my file system for the classes/ivars the linker is complaining about, I get matches in my static library file and my xcuserdata
workspace folders. So I am wondering if the issue is in my project, the library I am trying to import, or the way in which I am trying to add the library to my project? And also, why do I get linker errors when I am not even importing/calling the library from my code? I am using XCode 4.6.1
.
The linking error is as follows:
Undefined symbols for architecture armv7:
"_OBJC_IVAR_$_GenericPopupView.delegateTheme", referenced from:
-[MyListView setDelegateTheme:] in myLib.a(MyListView.o)
-[MyListView tableView:cellForRowAtIndexPath:] in myLib.a(MyListView.o)
"_OBJC_CLASS_$_SampleMarkView", referenced from:
objc-class-ref in myLib.a(MyListView.o)
"_OBJC_CLASS_$_CheckMarkView", referenced from:
objc-class-ref in myLib.a(MyListView.o)
"_OBJC_METACLASS_$_GenericPopupView", referenced from:
_OBJC_METACLASS_$_MyListView in myLib.a(MyListView.o)
"_OBJC_CLASS_$_GenericPopupView", referenced from:
_OBJC_CLASS_$_MyListView in myLib.a(MyListView.o)
ld: symbol(s) not found for architecture armv7
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I added the library to my target by performing the following steps:
- Right-click on my project
- Select
'Add Files to "My Project"'
- Locate the .a file through the popup Finder window
- Verify the library path is in my
Target -> Build Settings -> Library Search Paths
(automatically added when I complete step 3) - Add the header directory to
Target -> Build Settings -> Header Search Paths
- Verify that the library is listed in
Target -> Build Phases -> Link Binary With Libraries
Verify that the library is compiled for
armv7
viafile
,otool
, &lipo
(I heard the library may also includearmv6s
, but I didn't seearmv6
when I used the three commands)$ file myLib.a myLib.a: Mach-O universal binary with 2 architectures myLib.a (for architecture armv7): current ar archive random library myLib.a (for architecture cputype (12) cpusubtype (11)): current ar archive random library $ otool -L myLib.a Archive : myLib.a (architecture cputype (12) cpusubtype (11)) … $ lipo -info myLib.a Architectures in the fat file: myLib.a are: armv7 (cputype (12) cpusubtype (11))
Here are things I have tried inbetween each compile attempt without any success:
- Clean the project with (apple)+shift+k
- Clean the build directory (
DerivedData
) with (apple)+alt+shift+k - Delete all the
DerivedData
directories from the command line - Remove and re-add the library and its headers to my project
- Add the library without the headers
- Put the libraries in a project that is a target dependency instead of in my project directly
- Note that I am unable to add the library as a
Target Dependency
inBuild Settings
; should I be able to? - I am also unable to add the library to the target's
Build Scheme
(via XCode menu'sProduct -> Scheme -> Edit Scheme... -> Build -> +
)
- Note that I am unable to add the library as a
- Check the minimum iOS version via
iOS Deployment Target
inBuild Settings
– both my target and the library are iOS 6.0 Removed all target search paths except those required for my project to build without the new library as shown below (most importantly I removed the
DerivedData
from the linker path); my overall project build settings (not the target's build settings) contains no other search pathsHeader Search Paths
$(BUILT_PRODUCTS_DIR)/usr/local/include $(SRCROOT)/../MyLibDirectory/headers
Library Search Paths
$(inherited) $(SRCROOT)/../TargetDependencyDirectory $(SRCROOT)/../openssl/lib $(SRCROOT)/../MyLibDirectory
Removed all other instances of the library on my machine (old versions)
- Set the user-defined build setting
USE_HEADERMAP = NO
- Install on a newly imaged machine with a fresh project checkout and repeat all of the above steps
- Add
–ObjC++
to the other linker flags (-ObjC
is already a linker flag) - Use
armv6s
by itself and witharmv6
in theValid Architecture
underBuild Settings
for my target and the target dependencies - Set
Build Active Architecture Only
toYes
- Switched between adding the library in a project group vs. at the parent project group level
- Add an import and instantiation of an object from the library in my project code
- Played with the library's different settings for
Location
underIdentity and Type
in theUtilities
window on the right side of XCode when the library is selected - Add the library to the target's
Build Phases -> Link Binary With Libraries
via the+
thenAdd Other...
I have already tried the recommended steps in these and other posts (only the last two of these listed have actual instructions):
Xcode referencing old/removed frameworks, causing multiple interface declarations
- Undefined symbols for architecture armv7
I have not tried changing all of my files to .mm (I didn't need to for previous versions of this library), but I have a lot of .m files that I think might break if I change them all...
Any help or succestions are greatly appreciated! I'm really having a hard time figuring out why this new version of the library is giving me problems.