Bad Interaction between TemplateHaskell and FFI for cabal build
- Dominant language
- Haskell
- Stars
- 1.7k
- Forks
- 750
- Avg merge
- 4d 3h
- Merged PRs (30d)
- 28
Description
Here's an adaptation of Don Stewart's compiled constants example to demonstrate the issue:
[cabal-example](https://github.com/ecaustin/cabal-example).
When the project is loaded into ghci via `cabal repl` everything works fine.
However, when compiled via `cabal build` the following error is produced:
```
Building constants-0.1...
Preprocessing library constants-0.1...
[1 of 2] Compiling Constants ( Constants.hs, dist/build/Constants.o )
[2 of 2] Compiling Constants2 ( Constants2.hs, dist/build/Constants2.o )
dyld: lazy symbol binding failed: Symbol not found: _constant_cstring
Referenced from: /var/folders/dv/5spsnmzd7r51hbp2q4lkjb6m0000gn/T/ghc78711_0/libghc_6.dylib
Expected in: flat namespace
dyld: Symbol not found: _constant_cstring
Referenced from: /var/folders/dv/5spsnmzd7r51hbp2q4lkjb6m0000gn/T/ghc78711_0/libghc_6.dylib
Expected in: flat namespace
Trace/BPT trap: 5
```
Given that the code loads fine in GHCi, is there a flag, custom `Setup.hs`, or other workaround to get compilation to succeed?
As a note, this may or may not be related to an older cabal issue: [#1738](https://github.com/haskell/cabal/issues/1738).
Contributor guide
Research direction
Start with the linked cabal-example and reproduce the difference between cabal repl and cabal build, including the missing constant_cstring symbol. Read the older #1738 discussion and investigate whether a flag or custom Setup.hs is relevant. Done means the example builds successfully without the unresolved symbol.
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