views:

43

answers:

2

Hey guys, I made a custom Static Library that I use in my iPhone project. Everything works great except for when I use an NSKeyedUnarchiver to unarchive some data. It throws an exception when I try and use it in the library. I tried copying the classes of my static library into my project to see if that would work and it works fine but that defeats the purpose of a static library. I also tried lots of combinations of release/debug and simulator/device and still does not work. Is the NSKeyedUnarchiver having trouble finding the classes its trying to dearchive? Or does anyone know how to fix this? Do I maybe need to import stuff in the .m instead of the .h?

EDIT

Ok I tracked down the exception thrown and it says it is cant unarchive the class JGObjectRep which is one of the other classes in the static library. Keep in mind this works just fine if I copy these into the project.

+1  A: 

Sorry, I do not know the particularities of static libs used here, but here are some other thoughts I remember from other platforms.

First of all, the problem appears to be that the class information isn't fully available to the runtime system, hence the error.

Ergo, the static lib either doesn't include the needed information or the linker doesn't pass the information on. In the latter case, you're toast unless you can find extra linker options that enable such a feature. Hence, read the linker manual to see if there are related options.

In the former case, you could first look at the exported symbols with a tool (I believe "nm" can do this) to verify that the class name and its structure desciption is part of the symbols in the lib. I don't know how it has to look like, but maybe Google helps.

Another thought: Is that particular class being referenced by the main code? If not, the linker might not include it in the final code because it figures it's only used inside the static lib's environment and is thus not needed elsewhere. Hence, try to see if declarations either in the compiler's or linker's command options, or pragmas in source code, allow you to make this class globally known.

Good luck!

Thomas Tempelmann
Oh, and if you should figure it out, let us know, as I'm curious about this, too!
Thomas Tempelmann
+4  A: 

Try adding these options to your Linker Flags: -ObjC -all_load

Thomas Tempelmann
Ill try that thanks
Justin Meiners
Yep that did it could you explain what exactly that does?
Justin Meiners