CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build -o ./build/redis_full_check_agent_linux64 main.go # runtime/cgo linux_syscall.c:67:13: error: implicit declaration of function'setresgid' is invalid in C99 [-Werror,-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: implicit declaration of function'setresuid' is invalid in C99 [-Werror,-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 make: *** [linux] Error 2
CGO_ENABLED=1 GOOS=linux GOARCH=amd64 CC=x86_64-linux-musl-gcc CXX=x86_64-linux-musl-g++ go build -o BIN_NAME
运行程序
通过两个步骤就能正常交叉编译出linux二进制文件了,但上传ubuntu机器上运行可能会报错:
1 2
Failed to execute process './redis_full_check_agent_linux64'. Reason: The file './redis_full_check_agent_linux64' does not exist or could not be executed.