You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

MacOS下交叉编译Golang库至Linux失败求助

跨平台编译Go生成C共享库遇到的问题

查阅相关文章后,我尝试执行以下命令编译Go代码为Linux平台的C共享库:

env GOOS=linux GOARCH=amd64 go build -buildmode=c-shared -o hello.so  testlib.go

执行后出现错误:

go: no Go source files

随后我启用CGO重新执行命令:

env GOOS=linux GOARCH=amd64 CGO_ENABLED=1 go build -buildmode=c-shared -o hello.so testlib.go

但出现一系列编译错误:

env GOOS=linux GOARCH=amd64 CGO_ENABLED=1 go build -buildmode=c-shared -o hello.so testlib.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

环境版本信息

  • Go版本:go version go1.19.4 darwin/amd64
  • GCC版本:
=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/4.2.1
Apple clang version 12.0.0 (clang-1200.0.32.29)
Target: x86_64-apple-darwin19.6.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

内容的提问来源于stack exchange,提问作者Volatil3

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.06 07:40:23