knowledge-database (beta)

Current group: comp.lang.objective-c

Creating objective-c archives

Creating objective-c archives  
Tilo Prütz
 Re: Creating objective-c archives  
Christian Brunschen
 Re: Creating objective-c archives  
Tilo Prütz
 Re: Creating objective-c archives  
Christian Brunschen
 Re: Creating objective-c archives  
_
 Re: Creating objective-c archives  
Tilo_Prütz
 Re: Creating objective-c archives  
Michael Washington
 Re: Creating objective-c archives  
Tilo_Prütz
From:Tilo Prütz
Subject:Creating objective-c archives
Date:Tue, 16 Nov 2004 09:59:02 GMT
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
From:Christian Brunschen
Subject:Re: Creating objective-c archives
Date:16 Nov 2004 11:50:54 GMT
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?

Best wishes,

// Christian Brunschen
From:Tilo Prütz
Subject:Re: Creating objective-c archives
Date:Tue, 16 Nov 2004 12:30:58 GMT
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 -lobjc <-L/-l mylibs>


But I also could reproduce it with a minimal lib+app:
Compile + Link (lib):
gcc -c -o myCategory.o myCategory.m
ar -cr libCategory.a myCategory.o
ranlib libCategory.a

Compile + Link (app):
gcc -o myapp MyObject.m -L. -lCategory

An interesting point here is: In MyObject.m a method of myCategory is
called. But when linking myapp without the libCategory the linker does not
complain of missing symbols (I've moved the lib away from cwd to avoid
implicit linkage). The resulting binary has the same size as if I link with
-lCategory.


ar is: GNU ar 2.14.90.0.8 20040114
ranlib is: GNU ranlib 2.14.90.0.8 20040114


greetz

>tilo
From:Christian Brunschen
Subject:Re: Creating objective-c archives
Date:16 Nov 2004 14:32:06 GMT
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 -lobjc <-L/-l mylibs>
>
>
>But I also could reproduce it with a minimal lib+app:
>Compile + Link (lib):
>gcc -c -o myCategory.o myCategory.m
>ar -cr libCategory.a myCategory.o
>ranlib libCategory.a
>
>Compile + Link (app):
>gcc -o myapp MyObject.m -L. -lCategory

Hm. That looks all right to me. But then again, I mainly use Mac OS X, and
Frameworks rather than statically linked libraries.

>An interesting point here is: In MyObject.m a method of myCategory is
>called. But when linking myapp without the libCategory the linker does not
>complain of missing symbols (I've moved the lib away from cwd to avoid
>implicit linkage).

Categories only contain methods, which don't correspond to any public
symbols for the linker - remember, they are looked up by their selectors.
As long as when you compile code that sends the messages implemented by
the Category, you include the header file that declares those messages,
the compiler is happy - even if you don't actually have any
implementations of methods for those messages available at the time; the
actual resolution of selector -> implementing function is only done at
runtime.

>The resulting binary has the same size as if I link with
>-lCategory.

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.

>ar is: GNU ar 2.14.90.0.8 20040114
>ranlib is: GNU ranlib 2.14.90.0.8 20040114
>
>
>greetz

Beste Grüße,

>>tilo


// Christian
From:_
Subject:Re: Creating objective-c archives
Date:Wed, 17 Nov 2004 07:06:16 +1100
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.
From:Tilo_Prütz
Subject:Re: Creating objective-c archives
Date:Tue, 16 Nov 2004 22:06:09 +0100
Am Wed, 17 Nov 2004 07:06:16 +1100 schrieb _:

> 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.

Yeah! This helps!

Thank you very much.


greetz

>tilo
From:Michael Washington
Subject:Re: Creating objective-c archives
Date:Sat, 4 Dec 2004 01:40:22 GMT
Hello Tilo,

Thanks for your work

> 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
>>
From:Tilo_Prütz
Subject:Re: Creating objective-c archives
Date:Mon, 06 Dec 2004 11:23:12 +0100
Michael Washington wrote:

> Hello Tilo,
>
> Thanks for your work
>


Don't mention it.

greetz

>tilo


P.S.: my favo(u)rite: dict.leo.org ;)
   

Copyright © 2006 knowledge-database   -   All rights reserved