GHC API: Linker failure on loading target multiple times
Minimum Working Example: https://github.com/Fizzixnerd/ghc-bug
stack exec -- ghc --version
The Glorious Glasgow Haskell Compilation System, version 8.2.2
uname --all
Linux <REDACTED> 4.14.0-3-amd64 #1 (closed) SMP Debian 4.14.13-1 (2018-01-14) x86_64 GNU/Linux
Description: Loading a dynamic module more than once causes a linker failure with the following message:
'''
/usr/bin/ld.gold: error: cannot find -lghc_2
collect2: error: ld returned 1 exit status
gcc' failed in phase
Linker'. (Exit code: 1)
- ** Exception: ExitFailure 1
'''
-lghc_2' sometimes is
-lghc_5' or other numbers.
Steps to Reproduce:
- Clone above repo.
stack build
stack exec mwe-exe
The repo code will use the GHC API to load a string from the file contained in scripts/ named val
. There are three functions defined in src/Lib.hs. anotherFunc
should behave normally. `someFunc' should display the bad behavior.
Notes:
-
When using
intero
: intero must be restarted if this bug is encountered at the prompt, or else you will keep getting it over and over again. -
I could not figure out how to load it up without using the `-dynamic' flag, but that should probably be checked out too.