[Nix-dev] How to make "gcc -static ..." work

Bjørn Forsman bjorn.forsman at gmail.com
Wed Oct 12 15:40:19 CEST 2016


On 12 October 2016 at 15:37, Bjørn Forsman <bjorn.forsman at gmail.com> wrote:
> On 12 October 2016 at 15:30, Игорь Пашев <pashev.igor at gmail.com> wrote:
>> It requires libc.a Maybe you have to add glibc into the environment.
>
> Doh! Right... I thought libc was bundled with gcc, but of course, it's
> in _glibc_.
>
> Unfortunately, no celebration yet:
>
> $ nix-shell -p gcc glibc
> these paths will be fetched (9.83 MiB download, 19.98 MiB unpacked):
>   /nix/store/ia4g72xxpmnn9qj1v95af03ynll5addc-glibc-2.24-debug
>   /nix/store/wjzk9517pm6xl0pprdralf11hmxf4vkv-glibc-2.24-static
> fetching path ‘/nix/store/ia4g72xxpmnn9qj1v95af03ynll5addc-glibc-2.24-debug’...
> fetching path ‘/nix/store/wjzk9517pm6xl0pprdralf11hmxf4vkv-glibc-2.24-static’...
>
> So I can see it pulling in glibc-2.24-static, which contains libc.a
> (checked). Promising, but still:
>
> $ gcc -static foo.c
> /nix/store/nm9r5lymydnsrlxjn30ym2kix6mbyr19-binutils-2.27/bin/ld:
> cannot find -lc
> collect2: error: ld returned 1 exit status

An ugly hack / workaround:

$ nix-shell -p gcc glibc
$ gcc -L/nix/store/wjzk9517pm6xl0pprdralf11hmxf4vkv-glibc-2.24-static/lib
 -static

But I _really_ think nix/nixpkgs should be able to find the lib itself.

Best regards,
Bjørn Forsman


More information about the nix-dev mailing list