使用OS X上的cgo到linux和windows进行1.5交叉编译

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

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

使用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

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

解决方法

交叉编译时,默认情况下不启用cgo.如果启用cgo,CGO_ENABLED = 1,则需要为目标机器交叉编译c编译器.这不是一件轻而易举的事.

如果你需要cgo,我建议你本地编译.

dawei

【声明】:淮南站长网内容转载自互联网,其相关言论仅代表作者个人观点绝非权威,不代表本站立场。如您发现内容存在版权问题,请提交相关链接至邮箱:bqsm@foxmail.com,我们将及时予以处理。