Thank you for your reply. I already use both Other linker flags “-ObjC” and “-all_load” in the library, in its bundle target (though it is useless I think) and in the application including the library and the bundle with the nib. Then, I load the nib in the bundle by using :
> initWithNibName:nibName bundle:libraryBundle The other linker flags did solve the issue of categories in the library not visible in the application. The thing I don’t understand is that I get the warning, but my application works fine. It shouldn’t if NSView was indeed used instead of MyCustomView. Where do you put your linkerhack class ? In the library or in the app ? Thanks for your help – E > On Feb 22, 2015, at 05:45 , Roland King <r...@rols.org> wrote: > > >> On 22 Feb 2015, at 06:03, Erwin Namal <erwin.na...@gmail.com >> <mailto:erwin.na...@gmail.com>> wrote: >> >> Dear All, >> >> I am currently moving some of my app’s code out in a static library. I have >> subclasses of NSViewController and their nib. >> Searching on the net I fond a way to deal with the nibs, by adding a bundle >> target in the library for all the .xib files and importing the bundle as a >> resource in my app. >> Then, I can open the bundle and load the nibs. >> >> Now, when I do that, I get the following error in the console : >> >>> Unknown class ‘MyCustomView', using 'NSView' instead. Encountered in >>> Interface Builder file at path . . . . >> >> How can I fix it ? >> >> Thanks for your help >> – E > > > The problem with static libraries and xibs is that the linker doesn’t know > about the classes of objects in the xib so, if the class isn’t also > referenced in your source code somewhere, it doesn’t get linked in and so the > nib loading code can’t find it. This is a similar problem to using categories > in static libraries. > > The constantly-recommended ‘solution’ for this is to pass the -ObjC or > -all_load flags to the link. I hate that solution because it causes most or > all of the static library to be linked into the code, whether you need it or > not. Due to various bugs in the linker in times past there’s a trail of > advice to be found suggesting you specify both flags and people have been > gaily making huge fat binaries ever since. > > What I do in this case is ensure I have one source file (I usually call it > LINKERHACK.m) which has something like this in it > > @interface LINKERHACK : NSObject > +(void)loadClasses; > @end > > > @implementation LINKERHACK > +(void)loadClasses > { > Class __unused class1 = [ SomeStaticClass class ]; > } > @end > > > That’s enough to get the linker to pull in the class you want. I add classes > only found in the XIB into that list. I don’t believe you even need to call > the function anywhere, just compiling it in is enough to get the dependencies > the linker needs. Ugly, crude, but effective. > > I filed an enhancement request years ago that NIBs should be processed and > added to the link-time required symbols. I have lost hope of ever seeing that > happen. > _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com