[X-Unix] Compiling static binaries with GCC fails?

Philip J Robar philip.robar at gmail.com
Mon Sep 11 16:14:56 PDT 2006


On Sep 11, 2006, at 7:43 AM, Alexandre Gauthier wrote:

> Erm, bad practice to reply to myself, but I just figured something  
> out:
>
> On 11/09/06 10:37, "Alexandre Gauthier" <supernaut at underwares.org>  
> wrote:
>>
>> So I just invoke gcc with the -static option.
>>
>>   $ gcc -static -o program program.c
>>
> --snip--
>
> I browsed the gcc manpage and came across this:
>
>   -static
>     On systems that support dynamic linking, this prevents linking
>     with the shared libraries.  On other systems, this option has  
> no effect.
>
>     This option will not work on Mac OS X unless all libraries  
> (including
>     libgcc.a) have also been compiled with -static.  Since neither  
> a static
>     version of libSystem.dylib nor crt0.o are provided, this option  
> is not
>     useful to most people.
>
> Well this sort of sucks. It explains why the linker can't get its  
> greasy
> hands on crt0.o...
>
> Is there any way to get a static binary *at all* under OS X?

I'll second the question, "Why do want to do this?". On Solaris, for  
instance - as of version 10, you can't link statically anymore.  
(There's no libc.a.)

Also, OS X's dynamic linking is not like that of many other Unix's in  
that it has a 2 level name space. Apple has developer documents on  
this at the developer site. (First level membership is free.)


Phil



More information about the X-Unix mailing list