Confusion when it comes to static linking: A consumer library of static bindings cannot find the .a file
- Dominant language
- Haskell
- Stars
- 1.7k
- Forks
- 750
- Avg merge
- 4d 3h
- Merged PRs (30d)
- 28
Description
I am trying to bundle static libraries (`*.a`) files to a bindings library.
Reading the Cabal manual feels very confusing but I think I managed to do something that ought to be ± correct:
Cabal file stanza extract
```cabal
elif flag(bundled-libsodium)
extra-bundled-libraries: Csodium
include-dirs: include
install-includes:
include/sodium.h
include/sodium/core.h
include/sodium/crypto_aead_aes256gcm.h
[…]
```
With statically built archives in-tree: https://github.com/haskell-cryptography/libsodium-bindings/tree/37-libsodium-vendoring/libsodium-bindings/binaries
(For the curious: libsodium needs autotools to be built, and it is simply hell to accomodate this)
With a [custom setup](https://github.com/haskell-cryptography/libsodium-bindings/blob/37-libsodium-vendoring/libsodium-bindings/Setup.hs), I create the `libCsodium.a` archive in the build directory: `/tmp/libsodium-bindings/dist-newstyle/build/x86_64-linux/ghc-9.4.5/libsodium-bindings-0.0.1.0/build/libCsodium.a`
However I feel like I'm still missing some stuff because I end up seeing the following in a consumer of the haskell bindings:
```
/usr/bin/ld.gold: error: cannot find -lsodium
collect2: error: ld returned 1 exit status
`gcc' failed in phase `Linker'. (Exit code: 1)
```
But **not** in the bindings library itself.
Contributor guide
Research direction
Start with the Cabal stanza extract and the linked Setup.hs, then reproduce the consumer link failure using the stated build directory and libCsodium.a archive. Compare how the bindings library and its consumer resolve the static dependency; done means the consumer no longer reports that it cannot find -lsodium.
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
- Needs clarification
- Newbie friendliness
- 32/100