views:

312

answers:

2

I have a library I made, and now I want to utilize it in an application. I've believe I've properly linked to the library. Here are all the things I've done:

  • Set the header search path
  • Set other linker flags to "-ObjC"
  • Added the static library xcode project
  • Made sure the lib.a was listed as a framework target
  • Added the library as a direct dependency

Like I said in the title, I've successfully run the app with the static library in the simulator. Once I try testing the app using the device, it crashes the second it has to use a function from the library:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** +[NSDate firstOfCurrentMonth]: unrecognized selector sent to class 0x3841bb44'
2009-10-10 12:45:31.159 Basement[2372:207] Stack:
+2  A: 

This is due to a bug in the current SDK linker. See this post for more information on the problem and possible workarounds. (also see this post.)

Update:

Another thing you can try is to remove the static library and include the library's source files directly in the application's project. I was facing a similar static library linking issue and that's what I ended up falling back on to get it to run successfully. If that works (however gross a workaround it may be) then it's definitely a linker issue.

fbrereto
I tried that, it doesn't seem to help... I added that to the application and then the library.
spin-docta
As stated in the second link, you may need to add the "-all_load" option to the Other Linker Flags in your build settings to get categories from your static library to be linked in properly. This is a known issue with the iPhone OS 3.0 SDK.
Brad Larson
A: 

I ran into this problem recently. I was unable to get the -all_load to work, when I noticed that another category I had DID work. I was lazy for this category and included it in with another file.

I eventually created a dummy class (no methods, instance variables) and included the implementation of my categories in the .m file for that dummy class. After doing this my categories started working even after I removed the -all_load flag.

This was on iPhone OS 3.1.3.

This certainly is not the RIGHT way to fix it, but it seemed to work.

Full sample code is on my blog for my (trivial) categories.

Jon Lundy