【问题标题】:issue while creating go build for Mac from linux?从 linux 为 Mac 创建 go build 时出现问题?
【发布时间】:2019-06-23 09:50:13
【问题描述】:

我正在尝试从 linux 机器为 Mac 创建一个构建。我可以在不启用 CGO 的情况下通过以下常见操作来做到这一点。

env GOOS=darwin GOARCH=amd64 go build

使用启用 CGO 的命令

env CGO_ENABLED=1 GOOS=darwin GOARCH=amd64 go build

但如果我启用 CGO,那么它就不起作用并出现错误

# os/user
/usr/local/go/src/os/user/getgrouplist_darwin.go: In function 'mygetgrouplist':
/usr/local/go/src/os/user/getgrouplist_darwin.go:16:11: warning: implicit declaration of function 'getgrouplist' [-Wimplicit-function-declaration]
  int rv = getgrouplist(user, (int) group, buf, ngroups);
           ^
# net
/usr/local/go/src/net/cgo_bsd.go:15:72: could not determine kind of name for C.AI_MASK
# ConfigTool/Go/vendor/github.com/mattn/go-sqlite3
/tmp/go-build769992187/b129/_x011.o: In function `unixDlError':
vendor/github.com/mattn/go-sqlite3/sqlite3-binding.c:38475: undefined reference to `dlerror'
/tmp/go-build769992187/b129/_x011.o: In function `unixDlClose':
vendor/github.com/mattn/go-sqlite3/sqlite3-binding.c:38506: undefined reference to `dlclose'
/tmp/go-build769992187/b129/_x011.o: In function `unixDlSym':
vendor/github.com/mattn/go-sqlite3/sqlite3-binding.c:38502: undefined reference to `dlsym'
/tmp/go-build769992187/b129/_x011.o: In function `unixDlOpen':
vendor/github.com/mattn/go-sqlite3/sqlite3-binding.c:38461: undefined reference to `dlopen'
collect2: error: ld returned 1 exit status

【问题讨论】:

  • 我遇到了这个问题,因为我的 go 代码使用的是 Sqlite3。对于支持 sqlite 的构建来运行 CGO_ENABLED 不应为零。我没有找到解决此问题的方法,但我为 Mac 创建了一个单独的构建,并且该构建运行成功。

标签: linux macos shell go


【解决方案1】:

如果您要在 linux 上交叉编译 darwin 并且您正在使用 CGO_ENABLED=1,那么您还需要一个 C 交叉编译器。

https://github.com/golang/go/issues/22510#issuecomment-340938955

【讨论】:

  • 你能在这里了解什么是 C 交叉编译器,用于从 Alpine 编译针对 Mac 的二进制文件吗?
猜你喜欢
  • 1970-01-01
  • 2016-12-30
  • 2020-03-01
  • 2022-10-12
  • 1970-01-01
  • 1970-01-01
  • 2022-01-26
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多