登录
首页 >  Golang >  Go问答

从 linux 创建适用于 Mac 的 go build 时出现问题?

来源:stackoverflow

时间:2024-04-28 23:39:35 197浏览 收藏

怎么入门Golang编程?需要学习哪些知识点?这是新手们刚接触编程时常见的问题;下面golang学习网就来给大家整理分享一些知识点,希望能够给初学者一些帮助。本篇文章就来介绍《从 linux 创建适用于 Mac 的 go build 时出现问题?》,涉及到,有需要的可以收藏一下

问题内容

我正在尝试从 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

解决方案


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

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

以上就是《从 linux 创建适用于 Mac 的 go build 时出现问题?》的详细内容,更多关于的资料请关注golang学习网公众号!

声明:本文转载于:stackoverflow 如有侵犯,请联系study_golang@163.com删除
相关阅读
更多>
最新阅读
更多>
课程推荐
更多>