FontLabel icon indicating copy to clipboard operation
FontLabel copied to clipboard

Crash using static library

Open vbergae opened this issue 13 years ago • 2 comments

Hi, if I use FontLabel inside a static library the class FontLabel crashes on line 156:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[ZAttributedString sizeConstrainedToSize:lineBreakMode:numberOfLines:]: unrecognized selector sent to instance 0x633e670'

In another hand if I use FontLabel without static library, inside the main project, works great.

Any ideas?

vbergae avatar Apr 27 '11 10:04 vbergae

You're running into object file stripping. The simplest way to fix this is to tack -all_load onto your linker flags. You could also try -ObjC, but last I checked that flag didn't work correctly. You can try it yourself, they may have fixed it. You can also try -force_load path_to_archive if you don't want to use -all_load, but I'm not sure what the exact path needs to be. It may be something you can't easily figure out before building.

The basic problem here is ld omits object files from archives that don't appear to be used at link-time. This doesn't work with Obj-C, because of its dynamism. The -ObjC flag is supposed to instruct ld to always load object files that contain Obj-C data, but as I said before, it seems to be broken. -all_load tells ld to load all object files (note, dead code stripping can still strip out unused functions so it's not as bad as it sounds), and -force_load path_to_archive can tell ld to load all object files from the specified archive.

lilyball avatar Apr 27 '11 18:04 lilyball

This StackOverflow answer might be interesting as well.

lilyball avatar Apr 27 '11 18:04 lilyball