Hi there. My actual main goal is to build my own shared library written in Haskell that would be compatible with application written in C even without knowing that is is written in Haskell. So for now I compiled my shared library but I only could dynamically link it to Haskell dependencies such as "base" and "ghc-prim" packages. But I want to statically link Haskell dependencies but I realized it isn't simple and straightforward task.
On Freenode's #haskell I was advised I should build GHC from scratch with -fPIC, on the Linux (I'm using Fedora Workstation 25 on x86_64) I couldn't go forward without this step. So I wrote some Dockerfile based on Debian 9, skipping first part which is containing 'apt-get update' and installing 'build-essential' here is what I have:
COPY my-build.mk /my-build.mkAnd as you can see I just use my own prepared my-build.mk file which is:
SRC_HC_OPTS = -H64m -OI just combined it from parts I found in the internet during searching answers to my questions. So I built this container, I also installed dependencies by this commands:
cd /mntAnd when I tried to build my app by following commands (first command compiles some C-code to automatically initialize Haskell runtime, see link posted below, not sure if -static, -shared or -fPIC means something here but it's work in progress):
ghc -static -shared -fPIC -optc-DMODULE=Foo src/lib-autoinit.c -outputdir builddirI failed with a lot of similar errors like this one:
/usr/bin/ld.gold: error: /ghc-8.2.2-fpic/lib/ghc-8.2.2/ghc-prim-0.5.1.1/libHSghc-prim-0.5.1.1.a(Classes.o): requires dynamic R_X86_64_PC32 reloc against 'stg_ap_0_fast' which may overflow at runtime; recompile with -fPICWhat have I missed? What should I do to make this happen?
Any progress could be found here (Dockerfile, sources of modules,
build-scripts):
https://github.com/unclechu/haskell-experiment-shared-library-for-c-application
Related stack overflow issue:
https://stackoverflow.com/questions/47978884/how-do-i-recompile-ghc-with-fpic