Skip to content
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

Linker errors in stack release candidate 1.9.0.1 in static Linux binary #4318

Closed
donatello opened this issue Sep 25, 2018 · 14 comments
Closed

Comments

@donatello
Copy link

General summary/comments

stack returns linker errors when creating a new package:

Steps to reproduce

For example:

  1. On a freshly installed Ubuntu 18.04 VM, install https://github.com/commercialhaskell/stack/releases/download/v1.9.0.1/stack-1.9.0.1-linux-x86_64-static.tar.gz
  2. Run stack new test1
  3. Run cd test1 && stack build

Expected

The new project is setup and the build succeeds without any linker errors.

Actual

Got lots of linker errors (condensed below):

$ stack build                                                                                                                      Preparing to install GHC to an isolated location.   
This will not interfere with any system-level installation.                                                                                               Downloaded ghc-8.4.3.                         
Installed GHC.                                                                                                                                            
Linking /home/aditya/.stack/setup-exe-cache/x86_64-linux/tmp-Cabal-simple_mPHDZzAJ_2.2.0.1_ghc-8.4.3 ...
/usr/bin/x86_64-linux-gnu-ld.gold: error: cannot find -lgmp
/home/aditya/.stack/programs/x86_64-linux/ghc-8.4.3/lib/ghc-8.4.3/integer-gmp-1.0.2.0/libHSinteger-gmp-1.0.2.0.a(Type.o):integerzmgmp_GHCziIntegerziType_zdwplusBigNatWord_info: error: undefined reference to '__gmpn_add_1'
/home/aditya/.stack/programs/x86_64-linux/ghc-8.4.3/lib/ghc-8.4.3/integer-gmp-1.0.2.0/libHSinteger-gmp-1.0.2.0.a(Type.o):integerzmgmp_GHCziIntegerziType_zdwminusBigNatWord_info: error: undefined reference to '__gmpn_sub_1'
...
/home/aditya/.stack/programs/x86_64-linux/ghc-8.4.3/lib/ghc-8.4.3/integer-gmp-1.0.2.0/libHSinteger-gmp-1.0.2.0.a(wrappers.o):function integer_gmp_mpn_andn_n: error: undefined reference to '__gmpn_andn_n'
/home/aditya/.stack/programs/x86_64-linux/ghc-8.4.3/lib/ghc-8.4.3/integer-gmp-1.0.2.0/libHSinteger-gmp-1.0.2.0.a(wrappers.o):function integer_gmp_mpn_ior_n: error: undefined reference to '__gmpn_ior_n'
collect2: error: ld returned 1 exit status
`gcc' failed in phase `Linker'. (Exit code: 1)

--  While building simple Setup.hs using:
      /home/aditya/.stack/programs/x86_64-linux/ghc-8.4.3/bin/ghc -rtsopts -threaded -clear-package-db -global-package-db -hide-all-packages -package base -main-is StackSetupShim.mainOverride -package Cabal-2.2.0.1 /home/aditya/.stack/setup-exe-src/setup-mPHDZzAJ.hs /home/aditya/.stack/setup-exe-src/setup-shim-mPHDZzAJ.hs -o /home/aditya/.stack/setup-exe-cache/x86_64-linux/tmp-Cabal-simple_mPHDZzAJ_2.2.0.1_ghc-8.4.3
    Process exited with code: ExitFailure 1

Stack version

$ stack --version
Version 1.9.0.1, Git revision 4dee68538c3f6305d9531f4ad997d8c15b7f4434 (6125 commits) x86_64 hpack-0.31.0

Method of installation

Using the binary at https://github.com/commercialhaskell/stack/releases/download/v1.9.0.1/stack-1.9.0.1-linux-x86_64-static.tar.gz on Ubuntu

@borsboom
Copy link
Contributor

Have you tried the dynamically linked binary (https://github.com/commercialhaskell/stack/releases/download/v1.9.0.1/stack-1.9.0.1-linux-x86_64.tar.gz) with the same project?

@donatello
Copy link
Author

@borsboom Yes, and it works fine.

Note that I dont have any of my own code in the project. I just tried out the default project template - and it failed to build with the statically built stack version.

@borsboom
Copy link
Contributor

borsboom commented Sep 26, 2018

How strange, I've just tried to reproduce on a fresh Ubuntu 18.04 system, but the static stack is working just fine for me.

root@630fb349ec1a:~/test1# stack build
Preparing to install GHC to an isolated location.
This will not interfere with any system-level installation.
Downloaded ghc-8.4.3.
Installed GHC.
[1 of 2] Compiling Main             ( /root/.stack/setup-exe-src/setup-mPHDZzAJ.hs, /root/.stack/setup-exe-src/setup-mPHDZzAJ.o )
[2 of 2] Compiling StackSetupShim   ( /root/.stack/setup-exe-src/setup-shim-mPHDZzAJ.hs, /root/.stack/setup-exe-src/setup-shim-mPHDZzAJ.o )
Linking /root/.stack/setup-exe-cache/x86_64-linux/tmp-Cabal-simple_mPHDZzAJ_2.2.0.1_ghc-8.4.3 ...
Building all executables for `test1' once. After a successful build of all of them, only specified executables will be rebuilt.
test1-0.1.0.0: configure (lib + exe)
Configuring test1-0.1.0.0...
test1-0.1.0.0: build (lib + exe)
Preprocessing library for test1-0.1.0.0..
Building library for test1-0.1.0.0..
[1 of 2] Compiling Lib              ( src/Lib.hs, .stack-work/dist/x86_64-linux/Cabal-2.2.0.1/build/Lib.o )
[2 of 2] Compiling Paths_test1      ( .stack-work/dist/x86_64-linux/Cabal-2.2.0.1/build/autogen/Paths_test1.hs, .stack-work/dist/x86_64-linux/Cabal-2.2.0.1/build/Paths_test1.o )
ignoring (possibly broken) abi-depends field for packages
Preprocessing executable 'test1-exe' for test1-0.1.0.0..
Building executable 'test1-exe' for test1-0.1.0.0..
[1 of 2] Compiling Main             ( app/Main.hs, .stack-work/dist/x86_64-linux/Cabal-2.2.0.1/build/test1-exe/test1-exe-tmp/Main.o )
[2 of 2] Compiling Paths_test1      ( .stack-work/dist/x86_64-linux/Cabal-2.2.0.1/build/test1-exe/autogen/Paths_test1.hs, .stack-work/dist/x86_64-linux/Cabal-2.2.0.1/build/test1-exe/test1-exe-tmp/Paths_test1.o )
Linking .stack-work/dist/x86_64-linux/Cabal-2.2.0.1/build/test1-exe/test1-exe ...
test1-0.1.0.0: copy/register
Installing library in /root/test1/.stack-work/install/x86_64-linux/lts-12.10/8.4.3/lib/x86_64-linux-ghc-8.4.3/test1-0.1.0.0-GIjl8rJhn7R8Ydim5hVnal
Installing executable test1-exe in /root/test1/.stack-work/install/x86_64-linux/lts-12.10/8.4.3/bin
Registering library for test1-0.1.0.0..
root@630fb349ec1a:~/test1# stack --version
Version 1.9.0.1, Git revision 4dee68538c3f6305d9531f4ad997d8c15b7f4434 (6125 commits) x86_64 hpack-0.31.0
root@630fb349ec1a:~/test1# ldd `which stack`
	not a dynamic executable
root@630fb349ec1a:~/test1# grep DESCRIPTION /etc/lsb-release
DISTRIB_DESCRIPTION="Ubuntu 18.04.1 LTS"

@nh2
Copy link
Collaborator

nh2 commented Sep 27, 2018

/usr/bin/x86_64-linux-gnu-ld.gold: error: cannot find -lgmp suggests libgmp.so isn't avaiable at all on the system.

@donatello @borsboom Can you both post the output of aptitude search libgmp (perhaps after apt-get install aptitude), so we can compare?

@nh2
Copy link
Collaborator

nh2 commented Sep 27, 2018

An older ticket, perhaps related: haskell/cabal#5280

@nh2
Copy link
Collaborator

nh2 commented Sep 27, 2018

Another thing that we probably want to compare afterwards are the ghc invocations started by the static and dynamic stack.

@georgreen
Copy link

Fresh install on mac os and I have what seems to be a linker error. All stack command fails.
@borsboom @donatello @nh2 any help on this?

stack setup
clang: warning: argument unused during compilation: '-nopie' [-Wunused-command-line-argument]
clang: warning: argument unused during compilation: '-nopie' [-Wunused-command-line-argument]
ld64.lld: warning: ignoring unknown argument: --gc-sections
ld64.lld: warning: ignoring unknown argument: -u
ld64.lld: warning: ignoring unknown argument: -u
ld64.lld: warning: ignoring unknown argument: -u
ld64.lld: warning: ignoring unknown argument: -u
ld64.lld: warning: ignoring unknown argument: -u
ld64.lld: warning: ignoring unknown argument: -u
ld64.lld: warning: ignoring unknown argument: -u
ld64.lld: warning: ignoring unknown argument: -u
ld64.lld: warning: ignoring unknown argument: -u
ld64.lld: warning: ignoring unknown argument: -u
ld64.lld: warning: ignoring unknown argument: -u
ld64.lld: warning: ignoring unknown argument: -u
ld64.lld: warning: ignoring unknown argument: -u
ld64.lld: warning: ignoring unknown argument: -u
ld64.lld: warning: ignoring unknown argument: -u
ld64.lld: warning: ignoring unknown argument: -u
ld64.lld: warning: ignoring unknown argument: -u
ld64.lld: warning: ignoring unknown argument: -u
ld64.lld: warning: ignoring unknown argument: -u
ld64.lld: warning: ignoring unknown argument: -u
ld64.lld: warning: ignoring unknown argument: -u
ld64.lld: warning: ignoring unknown argument: -u
ld64.lld: warning: ignoring unknown argument: -u
ld64.lld: warning: ignoring unknown argument: -u
ld64.lld: warning: ignoring unknown argument: -u
ld64.lld: warning: ignoring unknown argument: -u
ld64.lld: warning: ignoring unknown argument: -u
ld64.lld: warning: ignoring unknown argument: -u
ld64.lld: warning: ignoring unknown argument: -u
ld64.lld: warning: ignoring unknown argument: -u
ld64.lld: warning: ignoring unknown argument: -u
ld64.lld: warning: ignoring unknown argument: -u
ld64.lld: warning: ignoring unknown argument: -u
ld64.lld: warning: ignoring unknown argument: -u
ld64.lld: warning: ignoring unknown argument: -u
ld64.lld: warning: ignoring unknown argument: -u
ld64.lld: warning: ignoring unknown argument: -u
ld64.lld: warning: ignoring unknown argument: -u
ld64.lld: warning: ignoring unknown argument: -u
ld64.lld: warning: ignoring unknown argument: -u
ld64.lld: warning: ignoring unknown argument: -u
ld64.lld: warning: ignoring unknown argument: -u
ld64.lld: warning: ignoring unknown argument: -u
ld64.lld: warning: ignoring unknown argument: -u
ld64.lld: warning: ignoring unknown argument: -u
ld64.lld: warning: ignoring unknown argument: -u
ld64.lld: warning: ignoring unknown argument: -u
ld64.lld: warning: ignoring unknown argument: -u
ld64.lld: warning: ignoring unknown argument: -u
ld64.lld: warning: ignoring unknown argument: -u
ld64.lld: warning: ignoring unknown argument: -u
ld64.lld: warning: ignoring unknown argument: -u
ld64.lld: warning: ignoring unknown argument: -u
ld64.lld: warning: ignoring unknown argument: -u
ld64.lld: warning: ignoring unknown argument: -u
ld64.lld: warning: ignoring unknown argument: -u
ld64.lld: warning: ignoring unknown argument: -u
ld64.lld: warning: ignoring unknown argument: -u
ld64.lld: warning: ignoring unknown argument: -u
ld64.lld: warning: ignoring unknown argument: -u
ld64.lld: warning: ignoring unknown argument: -u
ld64.lld: warning: ignoring unknown argument: -u
ld64.lld: warning: ignoring unknown argument: -u
ld64.lld: warning: ignoring unknown argument: -u
ld64.lld: warning: ignoring unknown argument: -u
ld64.lld: warning: ignoring unknown argument: -u
ld64.lld: warning: ignoring unknown argument: -u
ld64.lld: warning: ignoring unknown argument: -u
ld64.lld: warning: ignoring unknown argument: -u
ld64.lld: warning: ignoring unknown argument: -u
ld64.lld: warning: ignoring unknown argument: -u
ld64.lld: warning: ignoring unknown argument: -u
ld64.lld: warning: ignoring unknown argument: -u
ld64.lld: warning: ignoring unknown argument: -u
ld64.lld: warning: ignoring unknown argument: -u
ld64.lld: warning: ignoring unknown argument: -u
ld64.lld: warning: ignoring unknown argument: -u
ld64.lld: warning: ignoring unknown argument: -search_paths_first
ld64.lld: warning: -sdk_version is required when emitting min version load command.  Setting sdk version to match provided min version
Cannot open /private/var/folders/6y/_qflg4xj41sbkw8fgqb7wz300000gn/T/stack-sanity-check7680/Main.o: bad relocation (Invalid pointer diff) in section __TEXT/__text (r1_address=e0, r1_type=5, r1_extern=1, r1_length=3, r1_pcrel=0, r1_symbolnum=17), (r2_address=e0, r2_type=0, r2_extern=1, r2_length=3, r2_pcrel=0, r2_symbolnum=7)
clang: error: linker command failed with exit code 1 (use -v to see invocation)
`gcc' failed in phase `Linker'. (Exit code: 1)
The GHC located at /Users/georgreen/.stack/programs/x86_64-osx/ghc-8.4.3/bin/ghc failed to compile a sanity check. Please see:

    http://docs.haskellstack.org/en/stable/install_and_upgrade/

for more information. Exception was:
Received ExitFailure 1 when running
Raw command: /Users/georgreen/.stack/programs/x86_64-osx/ghc-8.4.3/bin/ghc /private/var/folders/6y/_qflg4xj41sbkw8fgqb7wz300000gn/T/stack-sanity-check7680/Main.hs -no-user-package-db
Run from: /private/var/folders/6y/_qflg4xj41sbkw8fgqb7wz300000gn/T/stack-sanity-check7680/
Standard output:

[1 of 1] Compiling Main             ( /private/var/folders/6y/_qflg4xj41sbkw8fgqb7wz300000gn/T/stack-sanity-check7680/Main.hs, /private/var/folders/6y/_qflg4xj41sbkw8fgqb7wz300000gn/T/stack-sanity-check7680/Main.o )
Linking /private/var/folders/6y/_qflg4xj41sbkw8fgqb7wz300000gn/T/stack-sanity-check7680/Main ...

@borsboom
Copy link
Contributor

@georgreen The current issue specifically regards the Linux statically linked stack binary for v1.9.0.1. Please open a new issue for your problem.

@borsboom
Copy link
Contributor

@nh2 Here's my aptitude search libgmp output:

root@6a9d4d4541eb:~# aptitude search libgmp
i   libgmp-dev                                                      - Multiprecision arithmetic library developers tools
p   libgmp-ocaml                                                    - OCaml bindings for the GNU multiprecision arithmetic library
v   libgmp-ocaml-ah7j9                                              -
p   libgmp-ocaml-dev                                                - OCaml bindings for the GNU multiprecision arithmetic library
v   libgmp-ocaml-dev-ah7j9                                          -
i   libgmp10                                                        - Multiprecision arithmetic library
v   libgmp10-dev                                                    -
p   libgmp10-doc                                                    - Multiprecision arithmetic library example code
p   libgmp3-dev                                                     - Multiprecision arithmetic library developers tools
p   libgmpada5                                                      - Ada binding to the GNU MultiPrecision library: shared library
p   libgmpada7-dev                                                  - Ada binding to the GNU MultiPrecision library: development
i A libgmpxx4ldbl                                                   - Multiprecision arithmetic library (C++ bindings)

@nh2 nh2 changed the title Linker errors in stack release candidate 1.9.0.1 in static binary Linker errors in stack release candidate 1.9.0.1 in static Linux binary Sep 27, 2018
@donatello
Copy link
Author

@borsboom @nh2 The problem was because of libgmp-dev was not installed. So on another fresh system, the steps to build a new project with both the static and dynamic builds of stack were:

$ sudo apt install libgmp-dev build-essential
$ stack new test1
$ cd test1
$ stack build # This installed ghc-8.4.3

Thanks for the tip about libgmp-dev - we can close this as my problem is resolved. Apologies for the confusion about the dynamic build working fine.

@georgreen Please open a new issue - your issue is related to MacOS builds so I doubt it is related to this one. I am going ahead and closing this one - please feel free to reopen it in case you think it is related to this issue.

@borsboom
Copy link
Contributor

What I don't get, though, is why the dynamically linked stack did work on the same system? It should also need libgmp-dev.

@nh2
Copy link
Collaborator

nh2 commented Sep 27, 2018

Yes, what @borsboom said:

Apologies for the confusion about the dynamic build working fine.

@donatello, can you clarify whether the dynamic build actually did work fine, or whether this was a misunderstanding?

@donatello
Copy link
Author

@borsboom @nh2 It was a misunderstanding that the dynamic binary's build attempt worked without the libgmp library. I tried the steps again a bit more systematically on a fresh system and got a better understanding of what was happening.

@klequis
Copy link

klequis commented May 6, 2022

Same issue fresh install of Ubuntu 22.04. Installing libgmp-dev resolved it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants