neurocyte / ghc-android

Build scripts for building ghc cross compilers targeting Android
182 stars 29 forks source link

ld.gold: -shared and -r are incompatible #35

Open rhaps0dy opened 9 years ago

rhaps0dy commented 9 years ago

Hello. I am trying to compile the android-haskell-activity example. I get this error:

$ arm-linux-androideabi-cabal install
Configuring HaskellActivity-0.1.0.0...
Building HaskellActivity-0.1.0.0...
Preprocessing executable 'libhaskell.so' for HaskellActivity-0.1.0.0...
[1 of 1] Compiling HaskellActivity  ( src/HaskellActivity.hs, dist/build/libhaskell.so/libhaskell.so-tmp/HaskellActivity.o )
/opt/ghc/android-21/arm-linux-androideabi-4.8/bin/../lib/gcc/arm-linux-androideabi/4.8/../../../../arm-linux-androideabi/bin/ld.gold: fatal error: -shared and -r are incompatible
collect2: error: ld returned 1 exit status
cabal: Error: some packages failed to install:
HaskellActivity-0.1.0.0 failed during the building phase. The exception was:
ExitFailure 1

Because Android requires position independent code, I can't run it.

running ghc with the -fPIC option does not work either:

$ arm-unknown-linux-androideabi-ghc -fPIC Test.hs
<command line>: Can't use -fPIC or -dynamic on this platform

Any clues to what might be causing this?

wavewave commented 8 years ago

See my patch to GHC in the following. It's for GHC-7.10. I just commented out the GHC source code to produce the error message. I succeeded in making resultant exe run on my phone.

https://github.com/wavewave/nix-build-ghc-android/blob/351758503a4e76f4da753d9b641c83f52695f16b/enable-fPIC.patch

BTW, I made a nix expression of GHC cross compiler for android as you see from the repo.

ppelleti commented 7 years ago

I built a GHC 8.0.1 cross compiler with the above patch, and now I can do arm-unknown-linux-androideabi-ghc -fPIC Test.hs without getting the error about -fPIC. However, when I build this repo, I still get the same ld.gold: fatal error: -shared and -r are incompatible. Any idea how to fix it?