1.1. 问题1:CGO_ENABLED=1

设置CGO_ENABLED=1时,出现问题

# 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'?
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/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'?
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/unistd.h:595:6: note: 'setreuid' declared here

image-20220625162846204

1.1.1. 解决办法

参考 使用go语言进行交叉编译的时候遇到的一些问题

这是因为os本身系统库不兼容的问题,首先因为我是在macos上编译linux的版本,所以需要安装:

brew install FiloSottile/musl-cross/musl-cross

如果你是在macos上编译运行在win下的exe,那么需要安装:

brew install mingw-w64
==> Downloading https://homebrew.bintray.com/bottles/gmp-6.2.1.big_sur.bottle.tar.gz
==> Downloading from https://d29vzk4ow07wi7.cloudfront.net/6a44705536f25c4b9f8547d44d129ae3b3657755039966ad2b86b821e187c32c?response-content-dispositio

同时编译的参数也需要调整如下:

GOOS=linux GOARCH=amd64 CGO_ENABLED=1 CC=x86_64-linux-musl-gcc  CXX=x86_64-linux-musl-g++ go build -ldflags="-s -w" -trimpath -o release/githubMonitor_linux main.go

这个时候直接放到linux也是不能运行的,需要安装musl

sudo yum install -y musl-libc-static

sudo apt-get install -y musl musl-dev
Copyright © d4m1ts 2022 all right reserved,powered by Gitbook该文章修订时间: 2022-06-25 16:34:20

results matching ""

    No results matching ""