nh2 / static-haskell-nix

easily build most Haskell programs into fully static Linux executables
388 stars 36 forks source link

Cannot build my program statically #47

Closed filipg7777 closed 5 years ago

filipg7777 commented 5 years ago

I'm trying to build my program (https://gitlab.com/filipg/geval) statically using the approach with Stack (https://github.com/nh2/static-haskell-nix#building-stack-projects), see the default.nix file: https://gitlab.com/filipg/geval/blob/master/default.nix

Unfortunately, I got the following error:

[1 of 1] Compiling Main             ( app/Main.hs, dist/build/geval/geval-tmp/Main.o )
Linking dist/build/geval/geval ...
/nix/store/ljx5sayk6w0bpd1ahcf0rm5fj55cqafd-binutils-2.31.1/bin/ld: cannot find -lcairo
/nix/store/ljx5sayk6w0bpd1ahcf0rm5fj55cqafd-binutils-2.31.1/bin/ld: cannot find -llzma
collect2: error: ld returned 1 exit status
`cc' failed in phase `Linker'. (Exit code: 1)

Is there a simple way to overcome this problem?

nh2 commented 5 years ago

Hey, I managed to build your project statically:

https://gitlab.com/filipg/geval/merge_requests/3

Please let me know if it's working for you, then I'll merge #48.

nh2 commented 5 years ago

For my records, I had first tried to do it via pkg-config, like so:

export NIX_LDFLAGS="$(pkg-config --static --libs-only-l cairo) $NIX_LDFLAGS"

This required making them available via PKG_CONFIG_PATH, for which I used this:

final.haskell.lib.addPkgconfigDepends drv [ final.cairo final.pcre final.libxcb final.xorg.libpthreadstubs final.xorg.libXdmcp ];

But while that did add all the flags I needed, it also added some more that weren't available (and apparently unnecessary, given that I could link it with fewer -l flags as in the working approach above):

Linking dist/build/geval/geval ...
/nix/store/bprb8jwawnsfnrmjwvazl3r84869f0g3-binutils-2.31.1/bin/ld: cannot find -lGL
/nix/store/bprb8jwawnsfnrmjwvazl3r84869f0g3-binutils-2.31.1/bin/ld: cannot find -lgobject-2.0
/nix/store/bprb8jwawnsfnrmjwvazl3r84869f0g3-binutils-2.31.1/bin/ld: cannot find -lglib-2.0
/nix/store/bprb8jwawnsfnrmjwvazl3r84869f0g3-binutils-2.31.1/bin/ld: cannot find -lEGL
/nix/store/bprb8jwawnsfnrmjwvazl3r84869f0g3-binutils-2.31.1/bin/ld: cannot find -lGL
/nix/store/bprb8jwawnsfnrmjwvazl3r84869f0g3-binutils-2.31.1/bin/ld: cannot find -lXrender
/nix/store/bprb8jwawnsfnrmjwvazl3r84869f0g3-binutils-2.31.1/bin/ld: cannot find -lXext
/nix/store/bprb8jwawnsfnrmjwvazl3r84869f0g3-binutils-2.31.1/bin/ld: cannot find -lX11
/nix/store/bprb8jwawnsfnrmjwvazl3r84869f0g3-binutils-2.31.1/bin/ld: cannot find -lXau
/nix/store/bprb8jwawnsfnrmjwvazl3r84869f0g3-binutils-2.31.1/bin/ld: cannot find -lXdmcp
filipg7777 commented 5 years ago

Danke schön, works perfectly!

nh2 commented 4 years ago

Please let me know if it's working for you, then I'll merge #48.

48 merged.