CGO ARM cross compiling

I need to use OpenBLAS (very popular in scientific community). “making” this on an X86 development machine works perfectly and I can call functions from go. However, I need this on an ARM linux target. So, I’ve done this:
Find all installed packages for the ARM compiler: sudo aptitude search arm-linux-gnueabi
Purge ALL gnueabi versions: sudo apt-get purge --auto-remove gfortran-arm-linux-gnueabi, etc for any "installed"
Install only gnueabihf versions: sudo aptitude install gfortran-arm-linux-gnueabihf (this also installs gnueabihf gcc)
From the OpenBLAS directory: make CC=arm-linux-gnueabihf-gcc FC=arm-linux-gnueabihf-gfortran HOSTCC=gcc TARGET=CORTEXA9
Install the ARM libs: sudo make PREFIX=/usr/local install
The make runs to completion and I can install the ARM OpenBLAS library. I followed similar steps to get FFTW to cross-compile if anyone is interested.

Next, installing go for cross-compiling I did this:
export CGO_ENABLED=1
export CC_FOR_TARGET=arm-linux-gnueabihf-gcc
export GOGCCFLAGS="-fPIC -pthread -mfpu=vfp -mfloat-abi=hard --static"
export GOOS=linux
export GOARCH=arm
export GOARM=7
bash ./all.bash

go env shows:
GOGCCFLAGS=”-fPIC -marm -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build149148529=/tmp/go-build -gno-record-gcc-switches"
Notice the GOGCCFLAGS get mangled (see golang go issues 8161). I can work around that by specifying GOGCCFLAGS on the command line:
GOOS=linux GOARCH=arm GOARM=7 GOGCCFLAGS=”-fPIC -pthread -mfpu=vfp -mfloat-abi=hard --static” CC=arm-linux-gnueabihf-gcc CGO_LDFLAGS=”-L/usr/local/lib -lopenblas " go build -x rand_zgeev.go

However, when I copy this to the arm system, it does not run:
-sh: ./rand_zgeev: not found

Any ideas why this won’t run?

check if you have execution right chmod +x rand_zgeev

Your program uses the wrong dynamic link library, use file or ldd to check

I think the library is correct (cross-compiled for ARM w/o errors and installed in /usr/local/lib).
Here is a verbose build command – maybe it will show where I’m going wrong?

GOOS=linux GOARCH=arm GOARM=7 GOGCCFLAGS="-fPIC -pthread -mfpu=vfp -mfloat-abi=hard --static" CC=arm-linux-gnueabihf-gcc CGO_LDFLAGS="-L/usr/local/lib -lopenblas " go build -x rand_zgeev.go

mkdir -p $WORK/
mkdir -p $WORK/
cd /opt/Projects/Golang/src/
/usr/local/go/pkg/tool/linux_amd64/compile -o $WORK/ -trimpath $WORK -p -complete -buildid 6c055d2e9740c6544b28b3cf4c4870cd41009466 -D _/opt/Projects/Golang/src/ -I $WORK -pack ./blas.go
mkdir -p $WORK/
cd /opt/Projects/Golang/src/
/usr/local/go/pkg/tool/linux_amd64/compile -o $WORK/ -trimpath $WORK -p -complete -buildid 043187ad29bedcb192f612b1aad8880403c27965 -D _/opt/Projects/Golang/src/ -I $WORK -I /opt/Projects/Golang/pkg/linux_arm -pack ./lapack.go
mkdir -p $WORK/
mkdir -p $WORK/
cd /opt/Projects/Golang/src/
CGO_LDFLAGS="-L/usr/local/lib" “-lopenblas” /usr/local/go/pkg/tool/linux_amd64/cgo -objdir $WORK/ -importpath – -I $WORK/ -g -O2 clapack.go
cd $WORK
arm-linux-gnueabihf-gcc -fdebug-prefix-map=a=b -c trivial.c
arm-linux-gnueabihf-gcc -gno-record-gcc-switches -c trivial.c
cd /opt/Projects/Golang/src/
arm-linux-gnueabihf-gcc -I . -fPIC -marm -pthread -fmessage-length=0 -fdebug-prefix-map=$WORK=/tmp/go-build -gno-record-gcc-switches -I $WORK/ -g -O2 -g -O2 -o $WORK/ -c $WORK/
arm-linux-gnueabihf-gcc -I . -fPIC -marm -pthread -fmessage-length=0 -fdebug-prefix-map=$WORK=/tmp/go-build -gno-record-gcc-switches -I $WORK/ -g -O2 -g -O2 -o $WORK/ -c $WORK/
arm-linux-gnueabihf-gcc -I . -fPIC -marm -pthread -fmessage-length=0 -fdebug-prefix-map=$WORK=/tmp/go-build -gno-record-gcc-switches -I $WORK/ -g -O2 -g -O2 -o $WORK/ -c $WORK/
arm-linux-gnueabihf-gcc -I . -fPIC -marm -pthread -fmessage-length=0 -fdebug-prefix-map=$WORK=/tmp/go-build -gno-record-gcc-switches -o $WORK/ $WORK/ $WORK/ $WORK/ -L/usr/local/lib -lopenblas -pie
/usr/local/go/pkg/tool/linux_amd64/cgo -objdir $WORK/ -dynpackage clapack -dynimport $WORK/ -dynout $WORK/
cd $WORK
arm-linux-gnueabihf-gcc -no-pie -c trivial.c
cd /opt/Projects/Golang/src/
arm-linux-gnueabihf-gcc -I . -fPIC -marm -pthread -fmessage-length=0 -fdebug-prefix-map=$WORK=/tmp/go-build -gno-record-gcc-switches -o $WORK/ $WORK/ $WORK/ -L/usr/local/lib -Wl,-r -nostdlib -Wl,–build-id=none
/usr/local/go/pkg/tool/linux_amd64/compile -o $WORK/ -trimpath $WORK -p -buildid 0410d16a71794e4adda4dc79b817e6005054ff93 -D _/opt/Projects/Golang/src/ -I $WORK -I /opt/Projects/Golang/pkg/linux_arm -pack $WORK/ $WORK/ $WORK/
pack r $WORK/ $WORK/ # internal
mkdir -p $WORK/command-line-arguments/_obj/
mkdir -p $WORK/command-line-arguments/_obj/exe/
cd /opt/Projects/Golang/src/eigengb/src/rand_zgeev
/usr/local/go/pkg/tool/linux_amd64/compile -o $WORK/command-line-arguments.a -trimpath $WORK -p main -complete -buildid fcb02d09987afaddcee04c965656ad189e457292 -D _/opt/Projects/Golang/src/eigengb/src/rand_zgeev -I $WORK -I /opt/Projects/Golang/pkg/linux_arm -pack ./rand_zgeev.go
cd .
/usr/local/go/pkg/tool/linux_amd64/link -o $WORK/command-line-arguments/_obj/exe/a.out -L $WORK -L /opt/Projects/Golang/pkg/linux_arm -extld=arm-linux-gnueabihf-gcc -buildmode=exe -buildid=fcb02d09987afaddcee04c965656ad189e457292 $WORK/command-line-arguments.a
mv $WORK/command-line-arguments/_obj/exe/a.out rand_zgeev

Hi Dave -
Can you tell from my build details (next post) what’s wrong? Everything seems to build w/o errors, but it does not load on target (ArmCortexA8)
Any suggestions? I’m stuck.

Best regards-

What is the “linux_amd64/compile” doing in there?! That is my development machine, but I installed everything to target arm-linux-gnueabihf.

Did I mess up go install? From my first post I tried to ensure everything was arm-gnueabihf.

That’s the host compiler, it knows how to compile for all targets.

Try these things

look here. check down on the page how to cross compile for ARM from Linux. it’s an example similar with yours.

Thanks for the pointers – I’ll try it on my next work day. I’m not sure it will work, but it’s certainly worth a try! I’m not sure the OpenBLAS library will link to get the right executable, but I’m confident it’s “good” since the lengthy build process showed no warnings or errors. I’ll let you know how it goes.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.