Cross-Compiling LLVM on Ubuntu 18.04 LTS for Raspberry Pi 4 ARM on Raspberrian Buster?

I have a Haskell project called taskell I’d like to compile for the Raspberry Pi Buster. It doesn’t seem to have a binary release for ARM, I contacted the author of the project, and he told me to compile it myself.

In the past I have compiled binaries for different architectures on an x86_x64 with the resulting target binary generated for a different architecture;

For instance the target binary might be for something like an IA64 or an ARM processor using make and gcc to compile C++ code and copying the resulting binary to a machine of that architecture type would (most of the time; assuming dependencies fulfilled) allow it run.

I do this for different reasons, for instance on an I64 architecture, I didn’t want to install all the dependencies for compilation on a server. And in the case of ARM (that it being for a Raspberry Pi) I wouldn’t want to beause it would take such a long time to compile.


Now that said, I haven’t tired cross-compiling Haskell for ARM though the Haskell wiki appears to mention a docker image for doing so, and also a guide here. The guide seems a little out of date however, since I can’t seem to download build-dep that it requires.

(I’m running Ubuntu 18.04 LTS)

When I run apt-get update I get errors like this regarding the architecture:

Err:5 http://us.archive.ubuntu.com/ubuntu bionic/main armhf Packages                         
  404  Not Found [IP: 91.189.91.38 80]
Ign:6 http://us.archive.ubuntu.com/ubuntu bionic/restricted armhf Packages                   
Ign:7 http://us.archive.ubuntu.com/ubuntu bionic/universe armhf Packages                     
Ign:8 http://us.archive.ubuntu.com/ubuntu bionic/multiverse armhf Packages                   
Ign:43 http://us.archive.ubuntu.com/ubuntu bionic-backports/main armhf Packages              
Ign:44 http://us.archive.ubuntu.com/ubuntu bionic-backports/universe armhf Packages          
Err:27 http://us.archive.ubuntu.com/ubuntu bionic-updates/main armhf Packages                
  404  Not Found [IP: 91.189.91.38 80]
Ign:33 http://us.archive.ubuntu.com/ubuntu bionic-updates/restricted armhf Packages          
Ign:36 http://us.archive.ubuntu.com/ubuntu bionic-updates/universe armhf Packages            
Ign:39 http://us.archive.ubuntu.com/ubuntu bionic-updates/multiverse armhf Packages          
Err:43 http://us.archive.ubuntu.com/ubuntu bionic-backports/main armhf Packages              
  404  Not Found [IP: 91.189.91.38 80]
Ign:44 http://us.archive.ubuntu.com/ubuntu bionic-backports/universe armhf Packages          
Fetched 5,302 kB in 31s (173 kB/s)  

Also, what dpkg --add-architecture <armxx> command should I run to add multiple architectures? I ran armhf, but I think it caused some issues with the packages…but I tried to compile it anyway…

leeand00@puppetmaster:~/tmp/dev/projects/llvm/build$ cmake -DCMAKE_INSTALL_PREFIX=/home/leeand00/tmp/dev/llvm_bin -DLLVM_TARGET_ARCH=armhf ../

Followed by:

leeand00@puppetmaster:~/tmp/dev/projects/llvm/build$ cmake --build .

But that resulted in the following error after it compiled for quite a while…

[ 33%] Built target LLVMProfileData
Scanning dependencies of target LLVMPasses
[ 33%] Building CXX object lib/Passes/CMakeFiles/LLVMPasses.dir/PassBuilder.cpp.o
c++: internal compiler error: Killed (program cc1plus)
Please submit a full bug report,
with preprocessed source if appropriate.
See [<file:///usr/share/doc/gcc-7/README.Bugs>](file:///usr/share/doc/gcc-7/README.Bugs) for instructions.
lib/Passes/CMakeFiles/LLVMPasses.dir/build.make:62: recipe for target 'lib/Passes/CMakeFiles/LLVMPasses.dir/PassBuilder.cpp.o' failed
make[2]: *** [lib/Passes/CMakeFiles/LLVMPasses.dir/PassBuilder.cpp.o] Error 4
CMakeFiles/Makefile2:18886: recipe for target 'lib/Passes/CMakeFiles/LLVMPasses.dir/all' failed
make[1]: *** [lib/Passes/CMakeFiles/LLVMPasses.dir/all] Error 2
Makefile:151: recipe for target 'all' failed
make: *** [all] Error 2

I don’t know what the issue is; but I believe LLVM is used to compile Haskell projects, so if I get that compiled, I should be able to compile taskell

Does anybody have any insight into why it doesn’t compile? Is it my apt-get packages, or is there something else I need to install?

Ben recently wrote a blogpost about the state of GHC on ARM – I think it looks promising and there’s some helpful info in that post as well.

1 Like

I tried to follow the blog post you suggested, (and it doesn’t look like it’s cross compiling, it looks like he’s compiling it on a Raspberry Pi 4 (which I happen to have, and I have tried it out))

sudo apt-get install llvm-9

Install llvm (this ran fine).

And the tutorial continues:

$ wget http://downloads.haskell.org/~ghc/8.10.1/ghc-8.10.1-armv7-deb9-linux.tar.lz
$ tar -xf ghc-8.10.1-armv7-deb9-linux.tar.lz
$ cd ghc-8.10.1
$ ./configure CONF_CC_OPTS_STAGE2="-marm -march=armv7-a" CFLAGS="-marm -march=armv7-a"
checking build system type... arm7l-unknown-liunix-gnueabihf
checking host system type... arm7l-unknown-liunix-gnueabihf
checking target system type... arm7l-unknown-liunix-gnueabihf
Build platform inferred as: arm-unknown-linux
Host platform inferred as: arm-unknown-linux
Target platform inferred as: arm-unknown-linux
GHC build   : arm-uknown-linux
GHC host    : arm-uknown-linux
GHC target  : arm-uknown-linux
LLVM Target:armv7l-unknown-linux-gnueabihf
checking for path to top of build tree... /hom/pi/ghc-8.10.1
checking for a BSP-copatible install.. /usr/bin/install -c
checking for gfind... no
checking for find... /usr/bin/find
checking whether ln -s works... yes
checking for gsed... sed
checking for python3... /usr/bin/python3
checking for gcc... gcc
checking whether the C compiler work... no
configure: error: in `/home/pi/ghc-8.10.1`:
configure: error: C compiler cannot create executables
See `config.log` for more details

Why can’t I create executables? gcc is installed.

Who is Ben? Does he have a username?