报错场景:
# runtime/cgo
gcc_linux_amd64.c: In function '_cgo_sys_thread_start':
gcc_linux_amd64.c:61:2: error: unknown type name 'sigset_t'; did you mean '_sigset_t'?
61 | sigset_t ign, oset;
| ^~~~~~~~
| _sigset_t
gcc_linux_amd64.c:66:2: error: implicit declaration of function 'sigfillset' [-Werror=implicit-function-declaration]
66 | sigfillset(&ign);
| ^~~~~~~~~~
gcc_linux_amd64.c:61:16: error: unused variable 'oset' [-Werror=unused-variable]
61 | sigset_t ign, oset;
| ^~~~
cc1: all warnings being treated as errors
2021/05/14 14:28:20 FATAL ▶ 0008 exit status 2
# 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
# github.com/mattn/go-sqlite3
sqlite3-binding.c: In function 'sqlite3SelectNew':
sqlite3-binding.c:128049:10: warning: function may return address of local variable [-Wreturn-local-addr]
128049 | return pNew;
| ^~~~
sqlite3-binding.c:128009:10: note: declared here
128009 | Select standin;
| ^~~~~~~
针对Windows安装mingw-w64
kog@kogdeMacBook-Pro % 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
...
针对Linux安装FiloSottile/musl-cross/musl-cross
brew install FiloSottile/musl-cross/musl-cross
验证是否安装成功
kog@kogdeMacBook-Pro % which x86_64-w64-mingw32-gcc
/usr/local/bin/x86_64-w64-mingw32-gcc
编译
# 编译到Windows添加参数
CGO_ENABLED=1 CC=x86_64-w64-mingw32-gcc CXX=x86_64-w64-mingw32-g++ go build main.go
# 编译到Linux添加参数
CGO_ENABLED=1 GOARCH=amd64 CC=x86_64-linux-musl-gcc CXX=x86_64-linux-musl-g++ go build main.go
beego异常信息(一): 交叉编译 Windows报警异常
# github.com/mattn/go-sqlite3
sqlite3-binding.c: In function 'sqlite3SelectNew':
sqlite3-binding.c:128049:10: warning: function may return address of local variable [-Wreturn-local-addr]
128049 | return pNew;
| ^~~~
sqlite3-binding.c:128009:10: note: declared here
128009 | Select standin;
| ^~~~~~~
解决方案:
bee pack -be GOOS=windows -be CGO_CFLAGS="-g -O2 -Wno-return-local-addr" -be GOARCH=amd64 -be CGO_ENABLED=1 -be CC=x86_64-w64-mingw32-gcc -be CXX=x86_64-w64-mingw32-g++
beego异常信息(二): 交叉编译 Linux报警异常
# runtime/cgo
gcc_linux_amd64.c: In function '_cgo_sys_thread_start':
gcc_linux_amd64.c:61:2: error: unknown type name 'sigset_t'; did you mean '_sigset_t'?
61 | sigset_t ign, oset;
| ^~~~~~~~
| _sigset_t
gcc_linux_amd64.c:66:2: error: implicit declaration of function 'sigfillset' [-Werror=implicit-function-declaration]
66 | sigfillset(&ign);
| ^~~~~~~~~~
gcc_linux_amd64.c:61:16: error: unused variable 'oset' [-Werror=unused-variable]
61 | sigset_t ign, oset;
| ^~~~
cc1: all warnings being treated as errors
解决方案:
bee pack -be GOOS=linux -be CGO_LDFLAGS="-static" -be CGO_ENABLED=1 -be GOARCH=amd64 -be CC=x86_64-linux-musl-gcc -be CXX=x86_64-linux-musl-g++
此篇查阅数以千计的文章, 踩了无数的坑, 转载请注明出处, 感谢理解
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)