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

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


Hi all,

On Ubuntu, I can compile static binaries with "gcc -static foo.c". But on NixOS:

$ nix-shell -p gcc
$ gcc -static foo.c
/nix/store/nm9r5lymydnsrlxjn30ym2kix6mbyr19-binutils-2.27/bin/ld:
cannot find -lc
collect2: error: ld returned 1 exit status

How to fix it?

Things I tried:

* Googling "nixpkgs static gcc". Found nothing.

* Grepping the nixpkgs tree, hoping to see stdenvStatic or something.
Found reference to dontDisableStatic for autotools packages. (Do I
have to rebuild GCC for static linking?)

* Looked in the NixOS and nixpkgs manual. Found references to static
Haskell binaries, but not for plain old C.

Best regards,
Bjørn Forsman


More information about the nix-dev mailing list