haskell / haskell/cabal

Before testing if libraries link, do a vanilla run to check if the compiler is misconfigured

Open
#4,395 5 comments 0 reactions 0 assignees View on GitHub
attention: pr-welcome Cabal: cmd/configure
Dominant language
Haskell
Stars
1.7k
Forks
750
Avg merge
4d 3h
Merged PRs (30d)
28

Description

@angerman was reporting on IRC that Cabal couldn't find `iconv`, but everything seemed like it was in order. When he posted `-v3` logs, the true error came to light:

```
/Users/angerman/Projects/Haskell/ghc-ios-scripts/aarch64-linux-android-clang -fno-stack-protector '-fuse-ld=gold' -Wl,-z,noexecstack /var/folders/fv/xqjrpfj516n5xq_m_ljpsjx00000gn/T/14587779232007237709.c -o /var/folders/fv/xqjrpfj516n5xq_m_ljpsjx00000gn/T/8235644401115438165 '-D__GLASGOW_HASKELL__=803' '-Ddarwin_BUILD_OS=1' '-Dx86_64_BUILD_ARCH=1' -Idist-install/build/autogen -I/Users/angerman/tmp/libiconv-1.15/include -Iinclude -I. -I/Users/angerman/Projects/Haskell/obsidian/ghc/rts/dist/build -I/Users/angerman/Projects/Haskell/obsidian/ghc/includes -I/Users/angerman/Projects/Haskell/obsidian/ghc/includes/dist-derivedconstants/header -liconv -L/Users/angerman/tmp/libiconv-1.15/lib/.libs -L/Users/angerman/Projects/Haskell/obsidian/ghc/libraries/integer-simple/dist-install/build -L/Users/angerman/Projects/Haskell/obsidian/ghc/libraries/ghc-prim/dist-install/build -L/Users/angerman/Projects/Haskell/obsidian/ghc/rts/dist/build -Wall -fno-stack-protector -Wno-unknown-pragmas
/Users/angerman/Projects/Haskell/ghc-ios-scripts/aarch64-linux-android-clang
returned ExitFailure 1 with error message:
clang: error: invalid linker name in argument '-fuse-ld=gold'
/Users/angerman/Projects/Haskell/ghc-ios-scripts/aarch64-linux-android-clang -fno-stack-protector '-fuse-ld=gold' -Wl,-z,noexecstack /var/folders/fv/xqjrpfj516n5xq_m_ljpsjx00000gn/T/178448449274243042.c -o /var/folders/fv/xqjrpfj516n5xq_m_ljpsjx00000gn/T/1148079871137522503 -liconv -L/Users/angerman/tmp/libiconv-1.15/lib/.libs -L/Users/angerman/Projects/Haskell/obsidian/ghc/libraries/integer-simple/dist-install/build -L/Users/angerman/Projects/Haskell/obsidian/ghc/libraries/ghc-prim/dist-install/build -L/Users/angerman/Projects/Haskell/obsidian/ghc/rts/dist/build -Wall -fno-stack-protector -Wno-unknown-pragmas
/Users/angerman/Projects/Haskell/ghc-ios-scripts/aarch64-linux-android-clang
returned ExitFailure 1 with error message:
clang: error: invalid linker name in argument '-fuse-ld=gold'
/Users/angerman/Projects/Haskell/ghc-ios-scripts/aarch64-linux-android-clang -fno-stack-protector '-fuse-ld=gold' -Wl,-z,noexecstack /var/folders/fv/xqjrpfj516n5xq_m_ljpsjx00000gn/T/144128232716531729.c -o /var/folders/fv/xqjrpfj516n5xq_m_ljpsjx00000gn/T/823378840143542612 -liconv -L/Users/angerman/tmp/libiconv-1.15/lib/.libs -L/Users/angerman/Projects/Haskell/obsidian/ghc/libraries/integer-simple/dist-install/build -L/Users/angerman/Projects/Haskell/obsidian/ghc/libraries/ghc-prim/dist-install/build -L/Users/angerman/Projects/Haskell/obsidian/ghc/rts/dist/build -Wall -fno-stack-protector -Wno-unknown-pragmas
/Users/angerman/Projects/Haskell/ghc-ios-scripts/aarch64-linux-android-clang
returned ExitFailure 1 with error message:
clang: error: invalid linker name in argument '-fuse-ld=gold'
/Users/angerman/Projects/Haskell/ghc-ios-scripts/aarch64-linux-android-clang -fno-stack-protector '-fuse-ld=gold' -Wl,-z,noexecstack /var/folders/fv/xqjrpfj516n5xq_m_ljpsjx00000gn/T/8965443031474833169.c -o /var/folders/fv/xqjrpfj516n5xq_m_ljpsjx00000gn/T/12648177091998097157 -c '-D__GLASGOW_HASKELL__=803' '-Ddarwin_BUILD_OS=1' '-Dx86_64_BUILD_ARCH=1' -Idist-install/build/autogen -I/Users/angerman/tmp/libiconv-1.15/include -Iinclude -I. -I/Users/angerman/Projects/Haskell/obsidian/ghc/rts/dist/build -I/Users/angerman/Projects/Haskell/obsidian/ghc/includes -I/Users/angerman/Projects/Haskell/obsidian/ghc/includes/dist-derivedconstants/header -Wall -fno-stack-protector -Wno-unknown-pragmas
ghc-cabal: Missing dependency on a foreign library:
* Missing C library: iconv
This problem can usually be solved by installing the system package that
provides this library (you may need the "-dev" version). If the library is
already installed but in a non-standard location then you can use the flags
--extra-include-dirs= and --extra-lib-dirs= to specify where it is.
make[1]: *** [libraries/base/dist-install/package-data.mk] Error 1
make: *** [all] Error 2
```

The failure of `clang` had nothing to do with linking `iconv`: rather, it was failing because of `clang: error: invalid linker name in argument '-fuse-ld=gold'`.

The way to solve this problem is, before we test if any of the libraries fail the linker, FIRST check if we can build a vanilla C file at all. If we can't, that means that there's something wrong with the options: output the error message verbatim.

There's a few other lessons too:

1. Even after the failure, Cabal goes off and tries to compile the headers. This caused me to take more time to diagnose the problem, because the true "failure" was further up the scrollback. We should error more quickly.

2. The error message should suggest running at higher verbosity to see the error message the compiler output, or just unconditionally report the actual error that caused the problem. None of this cloak and dagger "I ran something but I'm not going to tell you what I did, neener-neener."

Also, can we *finally* get `keep-tmp-files` for Cabal? This thing where the temporary files disappear before I can look at them is really annoying.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.