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

报告相同问题?

悬赏问题

  • ¥20 iOS绕地区网络检测
  • ¥15 python验证码滑块图像识别
  • ¥15 根据背景及设计要求撰写设计报告
  • ¥15 QT6颜色选择对话框显示不完整
  • ¥20 能提供一下思路或者代码吗
  • ¥15 用twincat控制!
  • ¥15 请问一下这个运行结果是怎么来的
  • ¥15 单通道放大电路的工作原理
  • ¥30 YOLO检测微调结果p为1
  • ¥15 DS18B20内部ADC模数转换器