haskell / haskell/cabal

`extra-libraries-static` of dependencies is ignored when linking fully statically

Open
#11,224 4 comments 1 reaction 0 assignees View on GitHub
attention: pr-welcome cabal-install: cmd/build type: bug
Dominant language
Haskell
Stars
1.7k
Forks
750
Avg merge
4d 3h
Merged PRs (30d)
28

Description

## Context

* https://github.com/haskell/cabal/pull/6935#issuecomment-3315062151
* https://discourse.haskell.org/t/adding-template-haskell-library-produces-linker-error-on-alpine/13000

## Problem description

When linking executable A fully statically (`--enable-executable-static`) against a Haskell library B, which has defined `extra-libraries-static` (either explicitly or implicitly through `pkg-config`), then this information is not used when linking A.

Illustration:

```
+ executable A
- extra-libraries-static <- respected
- extra-libraries <- respected
+ library dependency B
- extra-libraries-static <- ignored
- extra-libraries <- respected
```

## Reproducer

https://github.com/hasufell/cabal-extra-libraries

## Error

This will produce errors as such:

```
/home/buildozer/aports/main/curl/src/curl-8.14.1/lib/curl_ntlm_core.c:378:0: error:
(.text+0x1f6): undefined reference to `DES_ecb_encrypt'
/usr/lib/gcc/x86_64-alpine-linux-musl/14.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: /home/buildozer/aports/main/curl/src/curl-8.14.1/lib/curl_ntlm_core.c:382:(.text+0x21b): undefined reference to `DES_ecb_encrypt'
collect2: error: ld returned 1 exit status
ghc-9.6.7: `gcc' failed in phase `Linker'. (Exit code: 1)
```

Full build log: https://gist.github.com/hasufell/71755429d3c617701e5a2b276cea5524

Contributor guide

Open the contributing guide

Research direction

Start with the cabal-extra-libraries reproducer and compare linking executable A with the metadata declared by library B. Trace how extra-libraries-static from dependencies is handled during --enable-executable-static linking, then verify the reproducer builds without the reported undefined references.

Written by the indexing model from the issue text.

Assessment

Tech stack
haskell
Domain
build-system
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.