Cross compiling GO

Hello,

Using:
$ go version
go version go1.21.5 linux/amd64

I’m able to cross compile straight go to an arm target using:

export GOARCH=arm
export GOOS=linux
go build

The code compiles and the object runs on the target.

However, with CGO_ENABLED=1 I run into issues with the gcc compiler. I add the following:

export CC=aarch64-linux-gnu-gcc-8

In this case I get an error from the gcc compiler:

aarch64-linux-gnu-gcc: error: unrecognized command line option ‘-marm’

I can build if I set the architecture to arm64, but in this case the object file will not run on the target.

Also, I get uname -m
armv7l

on the target. However, I’m unable to set GOARCH to armv7l.

My question is, is it possible to build targets with “C”: interfaces given these issues for the target?

Thanks!

You must use correct gcc for arm 32-bit (gcc-arm-linux-gnueabi, gcc-arm-linux-gnueabihf, …) , not 64-bit