douxie5176 2015-08-31 10:20
浏览 174
已采纳

在OS X上使用cgo到Linux和Windows进行1.5交叉编译

I'm having trouble compiling the git2go library on OS X to linux amd64 after upgrading go 1.4.2 to go 1.5.

I think this is about cross compiling any go app that uses C code with go 1.5.

Using CGO_ENABLED=1, I get:

$ 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)

Using -compiler=gccgo, I get:

$ 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

If not supplying any of those, I get:

$ 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

I installed go using homebrew, and I have the $GOPATH pointing to the default ~/go location, nothing fancy.

  • 写回答

2条回答 默认 最新

  • dsj2222222 2015-08-31 11:29
    关注

    cgo is not enabled by default when cross compiling. If you enable cgo, with CGO_ENABLED=1 you will need to have a cross compiling c compiler for the target machine. This is non trivial.

    I recommend, if you need cgo, to compile natively.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛