Skip to content

cabal install fails to statically link executable #11163

@m-ildefons

Description

@m-ildefons

Describe the bug

cabal build produces an executable file without problems.
cabal install fails to produce an executable file.

The project where this was observed consists of a library and an executable file and builds fine when dynamically linked. However when linking statically, only cabal build manages to locate the interface files. cabal install fails with errors:

Build profile: -w ghc-9.10.1 -O1
In order, the following will be built (use -v for more details):
 - hadolint-2.13.1 (lib) (requires build)
 - hadolint-2.13.1 (exe:hadolint) (requires build)
Starting     hadolint-2.13.1 (lib)
Building     hadolint-2.13.1 (lib)
Installing   hadolint-2.13.1 (lib)
Completed    hadolint-2.13.1 (lib)
Starting     hadolint-2.13.1 (exe:hadolint)
Building     hadolint-2.13.1 (exe:hadolint)

Failed to build exe:hadolint from hadolint-2.13.1.
Build log (
/github/home/.cache/cabal/logs/ghc-9.10.1/hadolint-2.13.1-e-hadolint-b66140065e6932d4dc419722b7fda95da4107374fa16b6ad3c74db93ca8133d0.log
):
Warning: hadolint.cabal:3:33: version with tags
Configuring executable 'hadolint' for hadolint-2.13.1...
Preprocessing executable 'hadolint' for hadolint-2.13.1...
Building executable 'hadolint' for hadolint-2.13.1...
[1 of 2] Compiling Main             ( app/Main.hs, dist/build/hadolint/hadolint-tmp/Main.o, dist/build/hadolint/hadolint-tmp/Main.dyn_o )
app/Main.hs:5:1: error: [GHC-47808]
    Failed to load dynamic interface file for Hadolint:
      Exception when reading interface file  /github/home/.local/state/cabal/store/ghc-9.10.1-8a6a/hadolint-2.13.1-e2c9b9e2bdef0372783b4fb8e8c42b2d7dae1a668a72a7a0854571ae36005c61/lib/Hadolint.dyn_hi
        /github/home/.local/state/cabal/store/ghc-9.10.1-8a6a/hadolint-2.13.1-e2c9b9e2bdef0372783b4fb8e8c42b2d7dae1a668a72a7a0854571ae36005c61/lib/Hadolint.dyn_hi: withBinaryFile: does not exist (No such file or directory)
  |
5 | import Hadolint (OutputFormat (..), printResults, DLSeverity (..))
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

app/Main.hs:6:1: error: [GHC-47808]
    Failed to load dynamic interface file for Hadolint.Config:
      Exception when reading interface file  /github/home/.local/state/cabal/store/ghc-9.10.1-8a6a/hadolint-2.13.1-e2c9b9e2bdef0372783b4fb8e8c42b2d7dae1a668a72a7a0854571ae36005c61/lib/Hadolint/Config.dyn_hi
        /github/home/.local/state/cabal/store/ghc-9.10.1-8a6a/hadolint-2.13.1-e2c9b9e2bdef0372783b4fb8e8c42b2d7dae1a668a72a7a0854571ae36005c61/lib/Hadolint/Config.dyn_hi: withBinaryFile: does not exist (No such file or directory)
  |
6 | import Hadolint.Config
  | ^^^^^^^^^^^^^^^^^^^^^^

app/Main.hs:11:1: error: [GHC-47808]
    Failed to load dynamic interface file for Hadolint.Rule:
      Exception when reading interface file  /github/home/.local/state/cabal/store/ghc-9.10.1-8a6a/hadolint-2.13.1-e2c9b9e2bdef0372783b4fb8e8c42b2d7dae1a668a72a7a0854571ae36005c61/lib/Hadolint/Rule.dyn_hi
        /github/home/.local/state/cabal/store/ghc-9.10.1-8a6a/hadolint-2.13.1-e2c9b9e2bdef0372783b4fb8e8c42b2d7dae1a668a72a7a0854571ae36005c61/lib/Hadolint/Rule.dyn_hi: withBinaryFile: does not exist (No such file or directory)
   |
11 | import qualified Hadolint.Rule as Rule
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

[2 of 2] Compiling Paths_hadolint   ( dist/build/hadolint/autogen/Paths_hadolint.hs, dist/build/hadolint/hadolint-tmp/Paths_hadolint.o, dist/build/hadolint/hadolint-tmp/Paths_hadolint.dyn_o )
Error: [Cabal-7125]
Failed to build exe:hadolint from hadolint-2.13.1. See the build log above for details.

To Reproduce

Observed e.g. with https://github.com/hadolint/hadolint

$ cabal build --only-dependencies --disable-shared --ghc-options='-split-sections -optl-static -fPIC'
$ cabal install --installdir="$HOME/.local/bin" --install-method=copy --overwrite-policy=always --enable-executable-static --disable-executable-dynamic --disable-shared --ghc-options='-split-sections -optl-static -optl-pthread -fPIC'

Expected behavior

cabal install should not fail on a build error, when cabal build works fine.

System information

OS: openSUSE Leap 15.6, Alpine 3.21.4
Cabal:

cabal-install version 3.12.1.0
compiled using version 3.12.1.0 of the Cabal library 

GHC: The Glorious Glasgow Haskell Compilation System, version 9.10.1

Additional context

Observed e.g. in CI pipelines here: https://github.com/m-ildefons/hadolint/actions/runs/16911622370/job/47914561261

Workaround is to simply use cabal build to produce the executable file and use cabal list-bin to locate the build result. Then manually install the build result.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions