-
-
Notifications
You must be signed in to change notification settings - Fork 13.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GHC Static linking does not work #3193
Comments
Ah, I didn't notice. See #3194. |
… Haskell binaries Pass '-optl-static -optl-pthread' to GHC to enable static linking. Fixes <NixOS#3193>. Further details can be found at <http://permalink.gmane.org/gmane.linux.distributions.nixos/13526>.
… Haskell binaries Pass '-optl-static -optl-pthread' to GHC to enable static linking. Fixes <NixOS#3193>. Further details can be found at <http://permalink.gmane.org/gmane.linux.distributions.nixos/13526>.
I've been following the changes here, I'll try the updates out as soon as I can. |
The current |
Great, I got a simple example working, however when trying to statically compile a more complicated example: /nix/store/bzvdg7g74rkw7p3zw3mqpp7ynnq4mxf1-binutils-2.23.1/bin/ld: cannot find -lpcre
/nix/store/bzvdg7g74rkw7p3zw3mqpp7ynnq4mxf1-binutils-2.23.1/bin/ld: cannot find -lmysqlclient
/nix/store/bzvdg7g74rkw7p3zw3mqpp7ynnq4mxf1-binutils-2.23.1/bin/ld: cannot find -lssl
/nix/store/bzvdg7g74rkw7p3zw3mqpp7ynnq4mxf1-binutils-2.23.1/bin/ld: cannot find -lcrypto
/nix/store/hb92nfw5iapmrgy7c12h04vhp6yqb85b-ghc-7.8.3/lib/ghc-7.8.3/rts-1.0/libHSrts.a(Linker.o): In function `internal_dlopen':
Linker.c:(.text+0x5c): warning: Using 'dlopen' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/nix/store/hb92nfw5iapmrgy7c12h04vhp6yqb85b-ghc-7.8.3/lib/ghc-7.8.3/unix-2.7.0.1/libHSunix-2.7.0.1.a(HsUnix.o): In function `__hsunix_getpwent':
HsUnix.c:(.text+0xb1): warning: Using 'getpwent' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/nix/store/hb92nfw5iapmrgy7c12h04vhp6yqb85b-ghc-7.8.3/lib/ghc-7.8.3/unix-2.7.0.1/libHSunix-2.7.0.1.a(HsUnix.o): In function `__hsunix_getpwnam_r':
HsUnix.c:(.text+0xc1): warning: Using 'getpwnam_r' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/nix/store/hb92nfw5iapmrgy7c12h04vhp6yqb85b-ghc-7.8.3/lib/ghc-7.8.3/unix-2.7.0.1/libHSunix-2.7.0.1.a(HsUnix.o): In function `__hsunix_getpwuid_r':
HsUnix.c:(.text+0xd1): warning: Using 'getpwuid_r' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/nix/store/zg76yaqw5jyqfpj87ndkyl8swsdw3bmg-haskell-network-ghc7.8.3-2.5.0.0-shared/lib/ghc-7.8.3/network-2.5.0.0/libHSnetwork-2.5.0.0.a(HsNet.o): In function `hsnet_getaddrinfo':
(.text+0x21): warning: Using 'getaddrinfo' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/nix/store/zg76yaqw5jyqfpj87ndkyl8swsdw3bmg-haskell-network-ghc7.8.3-2.5.0.0-shared/lib/ghc-7.8.3/network-2.5.0.0/libHSnetwork-2.5.0.0.a(BSD__266.o):(.text+0x7f): warning: Using 'gethostbyname' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/nix/store/zg76yaqw5jyqfpj87ndkyl8swsdw3bmg-haskell-network-ghc7.8.3-2.5.0.0-shared/lib/ghc-7.8.3/network-2.5.0.0/libHSnetwork-2.5.0.0.a(BSD__248.o): In function `c1q6p_info':
(.text+0xbd): warning: Using 'getprotobyname' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/nix/store/zg76yaqw5jyqfpj87ndkyl8swsdw3bmg-haskell-network-ghc7.8.3-2.5.0.0-shared/lib/ghc-7.8.3/network-2.5.0.0/libHSnetwork-2.5.0.0.a(BSD__231.o): In function `c1pYC_info':
(.text+0xb2): warning: Using 'getservbyname' 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'm guessing I need to have the following libraries: pcre, mysqlclient, ssl, crypto |
According to a stackoverflow commenter, staticly linked programs are much less portable (is this true?) So would it be better for a program that does something like the following: [cody@cody-nixos:~]$ ldd hello
linux-vdso.so.1 (0x00007fffde5fb000)
libgmp.so.10 => /nix/store/rgm3f9ih66b9b726kf1n1g4xx0gnv3rq-gmp-5.1.3/lib/libgmp.so.10 (0x00007f152fea5000)
libm.so.6 => /nix/store/94n64qy99ja0vgbkf675nyk39g9b978n-glibc-2.19/lib/libm.so.6 (0x00007f152fba4000)
librt.so.1 => /nix/store/94n64qy99ja0vgbkf675nyk39g9b978n-glibc-2.19/lib/librt.so.1 (0x00007f152f99c000)
libdl.so.2 => /nix/store/94n64qy99ja0vgbkf675nyk39g9b978n-glibc-2.19/lib/libdl.so.2 (0x00007f152f798000)
libc.so.6 => /nix/store/94n64qy99ja0vgbkf675nyk39g9b978n-glibc-2.19/lib/libc.so.6 (0x00007f152f3eb000)
libpthread.so.0 => /nix/store/94n64qy99ja0vgbkf675nyk39g9b978n-glibc-2.19/lib/libpthread.so.0 (0x00007f152f1cd000)
/nix/store/94n64qy99ja0vgbkf675nyk39g9b978n-glibc-2.19/lib/ld-linux-x86-64.so.2 (0x00007f1530128000)
[cody@cody-nixos:~]$ patchfor ubuntu hello
Patched hello to work on ubuntu
[cody@cody-nixos:~]$ ldd hello
linux-vdso.so.1 => (0x00007fffbebfe000)
libgmp.so.10 => /usr/lib/x86_64-linux-gnu/libgmp.so.10 (0x00007f27db51c000)
libffi.so.6 => /usr/lib/x86_64-linux-gnu/libffi.so.6 (0x00007f27db314000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f27db00d000)
librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007f27dae05000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f27dac01000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f27da83a000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f27da61c000)
/lib64/ld-linux-x86-64.so.2 (0x00007f27db79a000) Hm, notice the nix example doesn't have libffi. |
Yes, if you want to link |
@codygman: the key thing was that statically linking glibc might be a problem, as far as I understood the post. For the other libraries it should be fine, I think, and increasing portability. |
To link fully statically (using musl libc instead of glibc), see https://github.com/nh2/static-haskell-nix/ for an example. |
Marked this as a bug, because currently there is no way (easy or that I know of) to compile Haskell programs on nixos that work on other linuxes such as Ubuntu, Debian,or Red Hat.
I was of the opinion that:
Would give me a statically linked binary which works on *nix or most of them. However it seems that it uses nix specific linking even with -static specified:
I then learned about -optl-static and tried it:
The text was updated successfully, but these errors were encountered: