【问题标题】:go 1.5 cross compile using cgo on OS X to linux and windowsgo 1.5 在 OS X 上使用 cgo 交叉编译到 linux 和 windows
【发布时间】:2015-11-25 08:34:21
【问题描述】:

在将 go 1.4.2 升级到 go 1.5 后,我无法将 OS X 上的 git2go 库编译到 linux amd64。

我认为这是关于使用 go 1.5 交叉编译任何使用 C 代码的 go 应用程序。

使用CGO_ENABLED=1,我得到:

$ CGO_ENABLED=1 GOOS=linux GOARCH=amd64 ./script/with-static.sh go install ./...
# runtime/cgo
ld: unknown option: --build-id=none
clang: error: linker command failed with exit code 1 (use -v to see invocation)

使用-compiler=gccgo,我得到:

$ GOOS=linux GOARCH=amd64 ./script/with-static.sh go install -compiler gccgo ./...
go build github.com/libgit2/git2go: : fork/exec : no such file or directory

如果不提供这些,我会得到:

$ GOOS=linux GOARCH=amd64 ./script/with-static.sh go install ./...
can't load package: package github.com/libgit2/git2go: C source files not allowed when not using cgo or SWIG: wrapper.c

我使用自制软件安装了 go,我的 $GOPATH 指向默认的 ~/go 位置,没什么特别的。

【问题讨论】:

  • 在 qemu 或 virtualbox 上设置 arch linux 对于 linux 编译应该很简单,您可以按照 my guide 从那里交叉编译到 windows。跨度>
  • 如果您使用的是 1.5,您可能希望跳到最后一个编译步骤。
  • @OneOfOne 您的评论帮助很大,从 Linux 容器交叉编译 Windows 相当容易。谢谢。

标签: go cross-compiling libgit2 cgo gccgo


【解决方案1】:

交叉编译时默认不启用cgo。如果您启用 cgo,并且 CGO_ENABLED=1,您将需要为目标机器提供一个交叉编译的 c 编译器。这不是小事。

如果您需要 cgo,我建议您进行原生编译。

【讨论】:

    【解决方案2】:

    如果您需要 cgo 交叉编译,我会将您指向 xgo,我发现它非常有帮助。它不能 100% 用于我的用例,但对我的代码进行一些小的(与维护本机 VM 以进行交叉编译相比)更改就足够了。

    【讨论】:

      猜你喜欢
      • 2014-08-24
      • 2012-08-06
      • 2016-11-07
      • 1970-01-01
      • 1970-01-01
      • 2017-06-26
      • 1970-01-01
      • 2015-04-24
      • 1970-01-01
      相关资源
      最近更新 更多