Mac M1 解决Go交叉编译成linux文件报错问题

问题展示

# runtime/cgo
linux_syscall.c:67:13: error: call to undeclared function 'setresgid'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
linux_syscall.c:67:13: note: did you mean 'setregid'?
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/unistd.h:593:6: note: 'setregid' declared here
linux_syscall.c:73:13: error: call to undeclared function 'setresuid'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
linux_syscall.c:73:13: note: did you mean 'setreuid'?
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/unistd.h:595:6: note: 'setreuid' declared here

在这里插入图片描述

问题解决

1、brew下载编译成linux的所需环境

brew install FiloSottile/musl-cross/musl-cross     

这一步下载需要使用国内的镜像,我使用的是清华的镜像下载的,下载的过程中会因为一下问题中断,你直接在终端一直重新输入以上命令

2、如果还不行就需要配置go env

go env -w CC="x86_64-linux-musl-gcc"
go env -w CXX="x86_64-linux-musl-g++"
go env -w GOOS=linux
go env -w GOARCH=amd64
go env -w CGO_ENABLED='0'

在这里插入图片描述

这个问题搞了我两天基本上把所有的论坛都找了一个遍,最后通过go官网里面的issue的这个方式解决的。以后有问题还是用谷歌浏览器比较好!

本文来自网络,不代表协通编程立场,如若转载,请注明出处:https://net2asp.com/c3caff00e9.html