Cross-compiling for linux arm/7: clang error: argument unused during compilation '-marm'

Viewed 567

What is the reason and how to solve it? Please..

cmd : CGO_ENABLED=1 GOOS=linux GOARCH=arm GOARM=7 go build

output:

# runtime/cgo
clang: error: argument unused during compilation: '-marm' [-Werror,-Wunused-command-line-argument]
  • OS: macOS Big Sur
  • Golang verson: go1.17 darwin/amd64
1 Answers

Read the fine manual:

When cross-compiling, you must specify a C cross-compiler for cgo to use. You can do this by setting the generic CC_FOR_TARGET or the more specific CC_FOR_${GOOS}_${GOARCH} (for example, CC_FOR_linux_arm) environment variable when building the toolchain using make.bash, or you can set the CC environment variable any time you run the go tool.

So you need to specify the cross-compiler for CGo, e.g. like so:

ā€ƒCC=arm-linux-gnueabihf-gcc CGO_ENABLED=1 GOOS=linux GOARCH=arm GOARM=7 go build

For C++ code also add CXX=arm-linux-gnueabihf-g++.

You'll need to have gcc-arm-linux-gnueabihf and libc6-dev-armhf-cross packages installed for the above to work (on Linux, don't know about Mac).

Related