10

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.

Calin
  • 2,110
  • 1
  • 21
  • 36
  • 1
    Setting up arch linux on qemu or virtualbox should be trivial to compile for linux, and you can follow *my* [guide](http://www.limitlessfx.com/cross-compile-golang-app-for-windows-from-linux.html) to cross-compile from there to windows. – OneOfOne Aug 31 '15 at 14:56
  • 1
    You probably want to skip up to the last compile step if you're using 1.5. – OneOfOne Aug 31 '15 at 14:58
  • 1
    @OneOfOne your comment helped alot, it's fairly easy to cross compile for Windows from a Linux container. Thanks. – Calin Sep 23 '15 at 04:22

2 Answers2

12

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.

Dave Cheney
  • 5,575
  • 2
  • 18
  • 24
1

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.

Astockwell
  • 1,498
  • 13
  • 11