Re: Static linking of a custom glibc

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 04/06/2020 06:17, Mahmood Naderan via Gcc-help wrote:
>> This looks like more of a glibc question than a gcc question.  I would
>> suggest reading
>>   https://sourceware.org/glibc/wiki/Testing/Builds
>
> Yes I am able to link to the new glibc with "-Wl,-rpath" and "-Wl,--dynamic-linker ".
> But, even with the default libc on the system, I am not able to link statically.
> $ gcc -o test -Wl,--emit-relocs -Wl,-Bstatic test.o
> /usr/bin/ld: cannot find -lgcc_s/usr/bin/ld: cannot find -lgcc_s
> collect2: error: ld returned 1 exit status
>
> I ask that on glibc list, but it seems that this is a gcc related problem.I am confused...

What is that command supposed to do? You're telling GCC to compile and
link dynamically dynamically, but telling the linker to link
statically. if you want GCC to link statically you're going to have to
use -static. You're also going to have to compile statically, with
-static.

If I want to link statically with a custom libc, I can do this:

gcc -static hello.c -Wl,--as-needed /usr/lib64/libc.a -Wl,--no-as-needed

Use the GCC option -Wl,-Map,mapfile and you'll be able to see what
happens.

-- 
Andrew Haley  (he/him)
Java Platform Lead Engineer
Red Hat UK Ltd. <https://www.redhat.com>
https://keybase.io/andrewhaley
EAC8 43EB D3EF DB98 CC77 2FAD A5CD 6035 332F A671




[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux