views:

158

answers:

3

I'm referencing two static libraries. I build them in debug-simulator mode and all works well with my app. I then create debug-iphone builds and push my app to the device. It breaks with this error:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSCFString sizeWithCGFont:pointSize:constrainedToSize:]: unrecognized selector sent to instance 0x24320'

Then the SIGABRT error shows.

Why would this work fine on the simulator and only manifest on the device?

-- EDIT --

Finally figured out a work around, at least for running on the device but now not the simulator. The method that is throwing the exception is a class I'm using for fonts. It is part of staticLibA, for example, which is the library that was having issues. I included staticLibA as a reference in the target app and also the .m file of the problem class. I already had a reference to its header file, which is a category in NSString. Is that why it didn't work until I included the .m file?

If I try to run it in the simulator, I get a duplicate object error in the build output folder for the above class.

+2  A: 

I couldn't tell you why your issue is only presenting itself on the device at the moment - perhaps you need to clean both builds and try recompiling them?

In any case, the exception message shown is completely valid. There is no (public) method named -[NSString sizeWithCGFont:pointSize:constrainedToSize:]. Are you trying to call one of the sizeWithFont: methods on NSString anywhere?

Edit: Looks like the sizeWithCGFont:pointSize:constrainedToSize: is from cocos-2d, which I'm guessing would be one of your static libraries. The major significant different between simulator and device builds is the build architecture - the simulator's architecture is the architecture of your own machine (i386), while device builds are for armv6 or armv7. Are you sure your static libraries are built for the right architectures?

Sbrocket
Thanks. I'm not using cocos2d. These two libraries are some I created. I noticed on the problem library that its debug-device build was set for i386. I changed it to the same as the working library - arm6/7. That didn't help. I then noticed Optimization level was set to "Fastest, smallest", while the working library was set to "None". I'll give it a try and post back results.
4thSpace
The optimization change didn't do anything. Still throwing the exception.
4thSpace
A: 

Simulator builds are compiled for the Intel platform since your computer is on the x86 (or x86_64) architecture.

The device builds compile to the arm6 (or arm7) architecture.

You can't use a library that's been compiled for one on the other. The assembly code from each isn't compatible.

Ben S
A: 

I have had this problem show up when I was releasing an object incorrectly. So I would have a pointer to a unallocated object. So when I called a function on the object, it would say that I was calling the function on a NSCFString object. Probably because the memory was reused for a NSString object. I fixed it by finding my extra release and removing it.

Eld
That issue should manifest regardless if you are on the simulator or device. I get the error on startup.
4thSpace