I have created an archive of objective-c objects using the following commands:
ar -cr libfoo.a bar.o ranlibg libfoo.a
I used this archive and everything worked well. Then I added a category to a class from another lib. This category is not initialized at runtime. The methods are not available. When I have a class and a category for this class in two different object files in an archive, this category is also not initialized:
ar -cr libfoo.a Bar.o categoryOfBar.o ranlib libfoo.a
When I have a class and a category for it in the same object file everything works well.
When I compile my libs as shared objects, everything works well.
Have I misused ar? Should objective-c archives be built another way? Or is this a bug? If, where? In ar, gcc or in the objective-c runtime?
In article , Tilo Prütz wrote: >Hi, > >I have created an archive of objective-c objects using the following >commands: > >ar -cr libfoo.a bar.o >ranlibg libfoo.a > >I used this archive and everything worked well. Then I added a category to a >class from another lib. This category is not initialized at runtime. The >methods are not available. >When I have a class and a category for this class in two different object >files in an archive, this category is also not initialized: > >ar -cr libfoo.a Bar.o categoryOfBar.o >ranlib libfoo.a > >When I have a class and a category for it in the same object file everything >works well. > >When I compile my libs as shared objects, everything works well. > >Have I misused ar? >Should objective-c archives be built another way? >Or is this a bug? If, where? In ar, gcc or in the objective-c runtime?
What platform are you using? What compiler, version, etc, including which Objective-C runtime system?
How exactly do you compile and link your final program?
In article <6qmmd.89$SK6.1703@se2-cb104-9.zrh1.ch.colt.net>, Tilo Prütz wrote: >Christian Brunschen wrote: >> What platform are you using? What compiler, version, etc, including which >> Objective-C runtime system? > >Platform: Linux >Compiler: gcc-3.4.2 >Runtime: GNU-Runtime (libobjc from gcc) > >> How exactly do you compile and link your final program? > >Compile (for all objects): >gcc -c -o myClass.o myClass.m -g -O2 -Werror -Wall -Wno-unknown-pragmas >-fno-strict-aliasing <-I myincludes> -std=gnu9x >-fconstant-string-class=myConstStringClass -Wno-protocol > >Link (for applications): >gcc -o myprog
Christian Brunschen wrote: > That sort of looks like the linker is discarding those libraries that > aren't explicitly referenced (through a symbol) by any other code. This is > beginning to look more like a gcc-specific problem than an Objective-C > language one, and I'm not the right person to help you there, alas.
If this is the case you could try using GNU ld's --whole-archive switch.
> Christian Brunschen wrote: >> That sort of looks like the linker is discarding those libraries that >> aren't explicitly referenced (through a symbol) by any other code. This is >> beginning to look more like a gcc-specific problem than an Objective-C >> language one, and I'm not the right person to help you there, alas. > > If this is the case you could try using GNU ld's --whole-archive switch. > > E.g. change the link command to look like, > > gcc -o myapp MyObject.m -L. -Wl,--whole-archive -lCategory > -Wl,--no-whole-archive ...other libs... > > The -Wl passes the text following the comma to the linker as > a command line argument.
> Hi, > > I have created an archive of objective-c objects using the following > commands: > > ar -cr libfoo.a bar.o > ranlibg libfoo.a > I used this archive and everything worked well. Then I added a > category to a > class from another lib. This category is not initialized at runtime. > The > methods are not available. > When I have a class and a category for this class in two different > object > files in an archive, this category is also not initialized: > ar -cr libfoo.a Bar.o categoryOfBar.o > ranlib libfoo.a > When I have a class and a category for it in the same object file > everything works well. > > When I compile my libs as shared objects, everything works well. > > Have I misused ar? > Should objective-c archives be built another way? > Or is this a bug? If, where? In ar, gcc or in the objective-c runtime? >> tilo >>