[Nix-dev] Statically linking haskell executable

Arseniy Seroka ars.seroka at gmail.com
Fri Oct 2 00:14:15 CEST 2015


Hello, guys!
Trying to compile and statically link haskell project executable.
I have in my .cabal file:
```
  GHC-Options:     -static
  Ld-Options:        -static -pthread
```

If I add `gtk` to the `Build-Depends` then I can't compile my project.
I'm getting:
```
Linking dist/build/foo/foo ...
/nix/store/kxf1p7l7lgm6j5mjzkiwcwzc98s9f1az-binutils-2.23.1/bin/ld: cannot
find -lgthread-2.0
/nix/store/kxf1p7l7lgm6j5mjzkiwcwzc98s9f1az-binutils-2.23.1/bin/ld: cannot
find -lpangocairo-1.0
/nix/store/kxf1p7l7lgm6j5mjzkiwcwzc98s9f1az-binutils-2.23.1/bin/ld: cannot
find -lgio-2.0
/nix/store/kxf1p7l7lgm6j5mjzkiwcwzc98s9f1az-binutils-2.23.1/bin/ld: cannot
find -lXrender
/nix/store/kxf1p7l7lgm6j5mjzkiwcwzc98s9f1az-binutils-2.23.1/bin/ld: cannot
find -lXinerama
/nix/store/kxf1p7l7lgm6j5mjzkiwcwzc98s9f1az-binutils-2.23.1/bin/ld: cannot
find -lXi
/nix/store/kxf1p7l7lgm6j5mjzkiwcwzc98s9f1az-binutils-2.23.1/bin/ld: cannot
find -lXrandr
/nix/store/kxf1p7l7lgm6j5mjzkiwcwzc98s9f1az-binutils-2.23.1/bin/ld: cannot
find -lXcursor
/nix/store/kxf1p7l7lgm6j5mjzkiwcwzc98s9f1az-binutils-2.23.1/bin/ld: cannot
find -lXcomposite
/nix/store/kxf1p7l7lgm6j5mjzkiwcwzc98s9f1az-binutils-2.23.1/bin/ld: cannot
find -lXdamage
/nix/store/kxf1p7l7lgm6j5mjzkiwcwzc98s9f1az-binutils-2.23.1/bin/ld: cannot
find -lXfixes
/nix/store/kxf1p7l7lgm6j5mjzkiwcwzc98s9f1az-binutils-2.23.1/bin/ld: cannot
find -lX11
/nix/store/kxf1p7l7lgm6j5mjzkiwcwzc98s9f1az-binutils-2.23.1/bin/ld: cannot
find -lXext
/nix/store/kxf1p7l7lgm6j5mjzkiwcwzc98s9f1az-binutils-2.23.1/bin/ld: cannot
find -latk-1.0
/nix/store/kxf1p7l7lgm6j5mjzkiwcwzc98s9f1az-binutils-2.23.1/bin/ld: cannot
find -lcairo
/nix/store/kxf1p7l7lgm6j5mjzkiwcwzc98s9f1az-binutils-2.23.1/bin/ld: cannot
find -lgdk_pixbuf-2.0
/nix/store/kxf1p7l7lgm6j5mjzkiwcwzc98s9f1az-binutils-2.23.1/bin/ld: cannot
find -lgio-2.0
/nix/store/kxf1p7l7lgm6j5mjzkiwcwzc98s9f1az-binutils-2.23.1/bin/ld: cannot
find -lpangoft2-1.0
/nix/store/kxf1p7l7lgm6j5mjzkiwcwzc98s9f1az-binutils-2.23.1/bin/ld: cannot
find -lpango-1.0
/nix/store/kxf1p7l7lgm6j5mjzkiwcwzc98s9f1az-binutils-2.23.1/bin/ld: cannot
find -lgobject-2.0
/nix/store/kxf1p7l7lgm6j5mjzkiwcwzc98s9f1az-binutils-2.23.1/bin/ld: cannot
find -lglib-2.0
/nix/store/kxf1p7l7lgm6j5mjzkiwcwzc98s9f1az-binutils-2.23.1/bin/ld: cannot
find -lfontconfig
/nix/store/kxf1p7l7lgm6j5mjzkiwcwzc98s9f1az-binutils-2.23.1/bin/ld: cannot
find -lpangocairo-1.0
/nix/store/kxf1p7l7lgm6j5mjzkiwcwzc98s9f1az-binutils-2.23.1/bin/ld: cannot
find -lcairo
/nix/store/kxf1p7l7lgm6j5mjzkiwcwzc98s9f1az-binutils-2.23.1/bin/ld: cannot
find -lpango-1.0
/nix/store/kxf1p7l7lgm6j5mjzkiwcwzc98s9f1az-binutils-2.23.1/bin/ld: cannot
find -lgobject-2.0
/nix/store/kxf1p7l7lgm6j5mjzkiwcwzc98s9f1az-binutils-2.23.1/bin/ld: cannot
find -lglib-2.0
/nix/store/kxf1p7l7lgm6j5mjzkiwcwzc98s9f1az-binutils-2.23.1/bin/ld: cannot
find -lgio-2.0
/nix/store/kxf1p7l7lgm6j5mjzkiwcwzc98s9f1az-binutils-2.23.1/bin/ld: cannot
find -lgobject-2.0
/nix/store/kxf1p7l7lgm6j5mjzkiwcwzc98s9f1az-binutils-2.23.1/bin/ld: cannot
find -lglib-2.0
/nix/store/kxf1p7l7lgm6j5mjzkiwcwzc98s9f1az-binutils-2.23.1/bin/ld: cannot
find -lgobject-2.0
/nix/store/kxf1p7l7lgm6j5mjzkiwcwzc98s9f1az-binutils-2.23.1/bin/ld: cannot
find -lglib-2.0
/nix/store/kxf1p7l7lgm6j5mjzkiwcwzc98s9f1az-binutils-2.23.1/bin/ld: cannot
find -lcairo
/nix/store/7hnlpxpmpka84zrhyq7z11bs0q3vgak1-ghc-7.10.2/lib/ghc-7.10.2/rts/libHSrts.a(Linker.o):
In function `internal_dlopen':
Linker.c:(.text+0x717): warning: Using 'dlopen' in statically linked
applications requires at runtime the shared libraries from the glibc
version used for linking
/nix/store/7hnlpxpmpka84zrhyq7z11bs0q3vgak1-ghc-7.10.2/lib/ghc-7.10.2/unix_A3WgcI5QiHK4PDo4jSYdwQ/libHSunix-2.7.1.0-A3WgcI5QiHK4PDo4jSYdwQ.a(HsUnix.o):
In function `__hsunix_getpwent':
HsUnix.c:(.text+0xa1): warning: Using 'getpwent' in statically linked
applications requires at runtime the shared libraries from the glibc
version used for linking
/nix/store/7hnlpxpmpka84zrhyq7z11bs0q3vgak1-ghc-7.10.2/lib/ghc-7.10.2/unix_A3WgcI5QiHK4PDo4jSYdwQ/libHSunix-2.7.1.0-A3WgcI5QiHK4PDo4jSYdwQ.a(HsUnix.o):
In function `__hsunix_getpwnam_r':
HsUnix.c:(.text+0xb1): warning: Using 'getpwnam_r' in statically linked
applications requires at runtime the shared libraries from the glibc
version used for linking
/nix/store/7hnlpxpmpka84zrhyq7z11bs0q3vgak1-ghc-7.10.2/lib/ghc-7.10.2/unix_A3WgcI5QiHK4PDo4jSYdwQ/libHSunix-2.7.1.0-A3WgcI5QiHK4PDo4jSYdwQ.a(HsUnix.o):
In function `__hsunix_getpwuid_r':
HsUnix.c:(.text+0xc1): warning: Using 'getpwuid_r' in statically linked
applications requires at runtime the shared libraries from the glibc
version used for linking
collect2: error: ld returned 1 exit status
```

I've changed my default nix like
```
let
  gtkStatic = pkgs.gnome.gtk.overrideDerivation (old: {
    dontDisableStatic = true;
    configureFlags = old.configureFlags + " --enable-static";
  });

  haskellPackages' = pkgs.haskellPackages.override {
    overrides = self: super: {
      gtk = super.gtk.override {
        mkDerivation = (attrs: self.mkDerivation (attrs // {
          libraryPkgconfigDepends = [ gtkStatic ];
          enableSharedLibraries = false;
        }));
      };
    };
  };
in
haskellPackages'.callPackage ./project.nix { }
``` where ./project.nix is a generated file by `cabal2nix`.
But that doesn't help.

How can I properly build static executable? I need to run it on the arch
linux.


-- 
Sincerely,
Arseniy Seroka
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.science.uu.nl/pipermail/nix-dev/attachments/20151002/bedb0cfc/attachment.html 


More information about the nix-dev mailing list