Question

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:

  1. Right-click on my project
  2. Select 'Add Files to "My Project"'
  3. Locate the .a file through the popup Finder window
  4. Verify the library path is in my Target -> Build Settings -> Library Search Paths (automatically added when I complete step 3)
  5. Add the header directory to Target -> Build Settings -> Header Search Paths
  6. Verify that the library is listed in Target -> Build Phases -> Link Binary With Libraries
  7. Verify that the library is compiled for armv7 via file, otool, & lipo (I heard the library may also include armv6s, but I didn't see armv6 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 in Build Settings; should I be able to?
    • I am also unable to add the library to the target's Build Scheme (via XCode menu's Product -> Scheme -> Edit Scheme... -> Build -> +)
  • Check the minimum iOS version via iOS Deployment Target in Build 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 paths

    Header 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 with armv6 in the Valid Architecture under Build Settings for my target and the target dependencies
  • Set Build Active Architecture Only to Yes
  • 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 under Identity and Type in the Utilities 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 + then Add Other...

I have already tried the recommended steps in these and other posts (only the last two of these listed have actual instructions):

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.

Était-ce utile?

La solution

I resolved my own problem, or rather, the issue was with the black box of a library that I was including. From the command line performed the following command in a terminal window:

grep SampleMarkView myLib.a

Which resulted in:

Binary File:myLib.a matches

I talked to the person who created the library and they sent me an updated version that didn't cause the problem - I guess they had old references in their code. So at the very least I hope this post provides a list of various things to try if you are having a library referencing problem!

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top