go 1.5 在 OS X 上使用 cgo 交叉编译到 linux 和 windows

标签 go cross-compiling libgit2 cgo gccgo

我在编译 git2go 时遇到问题升级 go 1.4.2 到 go 1.5 后,OS X 上的库到 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 位置,没有什么特别的。

最佳答案

交叉编译时默认不启用cgo。如果启用 cgo,则 CGO_ENABLED=1 您将需要为目标机器安装一个交叉编译的 c 编译器。这很重要。

如果你需要 cgo,我建议原生编译。

关于go 1.5 在 OS X 上使用 cgo 交叉编译到 linux 和 windows,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32309030/

相关文章:

git - libgit2 如何将短引用名称解析为完整引用名称或哈希

c - 在柯南构建步骤中选择构建类型

c# - GIT 智能 HTTP 协议(protocol)的服务端和客户端有哪些细节区别

go - 在 Go 中设置工厂模式

go - 使用多个数据库(DAO 模式)

linux - 链接器在传递给它的目标文件上删除字符?

c++ - os_defines.h : fatal error: features. h 没有这样的文件或目录

c++ - 如何在 C++ 中使用 libgit2 检查是否需要 pull?

sql - 将 int 转换为 int32

go - 默认结构用作 golang 中 yaml 数据的目的地