从Linux为Mac创建go build时出现问题?

时间:2019-01-30 07:13:24

标签: linux macos shell go

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

1 个答案:

答案 0 :(得分:0)

如果你要交叉编译为{{1}在darwin和你正在使用linux,那么你就需要一个CGO_ENABLED=1交叉编译器也。

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