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

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

这是什么原因,如何解决?请..

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

输出:

# runtime/cgo
clang: error: argument unused during compilation: '-marm' [-Werror,-Wunused-command-line-argument]

阅读 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.

所以你需要为CGo指定交叉编译器,例如像这样:

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

对于 C++ 代码还添加 CXX=arm-linux-gnueabihf-g++

您需要安装 gcc-arm-linux-gnueabihflibc6-dev-armhf-cross 包才能使上述工作正常(在 Linux 上,不知道 Mac)。