I've successfully created a ghc cross compiler, that allows me to compile haskell code for armv6h (raspberry pi in my case) from my x64 linux machine. I've successfully run a hello world program on the raspberry.
No I want to build my real app, which has a lot of dependencies on other haskell modules. When I compile for x64 I simply do
cabal install dependenciy1 depenency2 ...
I know I could make my own programm a cabal-project an automate this step. But that's not the point here.
When I try to use the cross-compiler
arm-unknown-linux-gnueabi-ghc --make myapp.hs
It tells me about modules it could not find. Of course, they are not installed!
I read https://ghc.haskell.org/trac/ghc/wiki/Building/CrossCompiling and according to that I tried
cabal --with-ghc=arm-unknown-linux-gnueabi-ghc --with-ghc-pkg=arm-unknown-linux-gnueabi-ghc-pkg --with-ld=arm-unknown-linux-gnueabi-ld install random
random is the depenency I'm trying to install here. I get the following error:
Resolving dependencies...
Configuring random-1.0.1.3...
Failed to install random-1.0.1.3
Last 10 lines of the build log ( /home/daniel/.cabal/logs/random-1.0.1.3.log ):
/home/daniel/.cabal/setup-exe-cache/setup-Cabal-1.18.1.3-arm-linux-ghc-7.8.3.20140804: /home/daniel/.cabal/setup-exe-cache/setup-Cabal-1.18.1.3-arm-linux-ghc-7.8.3.20140804: cannot execute binary file
cabal: Error: some packages failed to install:
random-1.0.1.3 failed during the configure step. The exception was:
ExitFailure 126
When I do
file /home/daniel/.cabal/setup-exe-cache/setup-Cabal-1.18.1.3-arm-linux-ghc-7.8.3.20140804
I get
/home/daniel/.cabal/setup-exe-cache/setup-Cabal-1.18.1.3-arm-linux-ghc-7.8.3.20140804: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 3.10.2, not stripped
No wonder it can't execute it. It's compiled for arm.
Am I missing something here? My goal is to pull in all dependencies, then create a statically linked app that I can deploy on my raspberry.
cabal get random
, then cd to therandom-???
directory, and thenrunhaskell ./Setup.hs install --with-ghc=... ...
? – Electrocardiogramunrecognized 'install' option `--with-ghc=arm-unknown-linux-gnueabi-ghc' unrecognized 'install' option `--with-ghc-pkg=arm-unknown-linux-gnueabi-ghc-pkg' unrecognized 'install' option `--with-ld=arm-unknown-linux-gnueabi-ld'
– Obstetricsrunhaskell ./Setup.hs configure --with...
, thenrunhaskell ./Setup.hs build
and finallyrunhaskell ./Setup.hs install
. – Electrocardiogram/home/daniel/x-tools/arm-unknown-linux-gnueabi/lib/gcc/arm-unknown-linux-gnueabi/4.8.2/../../../../arm-unknown-linux-gnueabi/bin/ld: skipping incompatible /home/daniel/.cabal/lib/arm-linux-ghc-7.8.3.20140804/random-1.0.1.3/libHSrandom-1.0.1.3.a when searching for -lHSrandom-1.0.1.3
– Obstetrics--disable-library-stripping
and--disable-executable-stripping
– Sixtyfourmohsc2hs
, make sure it gets-x
flag, otherwise it will produceStorable
instances for host architecture instead of target. IIRC I needed it fornetwork
, otherwise it crashed at runtime. – Sixtyfourmo