2015-08-31 10:20
浏览 127

在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/ 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/ go install -compiler gccgo ./...
go build : fork/exec : no such file or directory

If not supplying any of those, I get:

$ GOOS=linux GOARCH=amd64 ./script/ go install ./...
can't load package: package 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.

图片转代码服务由CSDN问答提供 功能建议

我在编译 git2go 库安装到OS X上的Linux amd64。

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

使用 CGO_ENABLED = 1 ,我得到:

 <代码> $ CGO_ENABLED = 1 GOOS = linux GOARCH = amd64 ./script/ go install ./...
# runtime / cgo  
ld:未知选项:--build-id = none 

使用 -compiler = gccgo ,我得到:

  $ GOOS = linux GOARCH = amd64 ./script  /with-static.sh去安装-compiler gccgo ./...
go建立 / exec:没有这样的文件或目录
 \  n 


 <代码> $ GOOS = linux GOARCH = amd64 ./script/with-static.sh转到install ./...
无法加载软件包:软件包  / git2go:不使用cgo或SWIG时不允许使用C源文件:wrapper.c 

我安装时使用自制软件,并且我有 $ GOPATH 指向默认的〜/ go 位置,没什么好看的。

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

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.

    打赏 评论
  • douxian9060 2016-02-07 03:30

    If you need cgo cross compilation, I'd point you to xgo, which I found immensely helpful. It didn't work in 100% of my use cases, but with some minor (compared to maintaining native VMs for cross-compiling) changes to my code, it was sufficient.

    打赏 评论

相关推荐 更多相似问题