Go 1.5 cross compilation with cgo on OS X on linux and windows

I had a problem compiling the git2go library on OS X to linux amd64 after the upgrade, go 1.4.2 to go to 1.5.

I think this is about cross-compiling any go application using 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 you do not supply any of them, 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 $GOPATH pointing to the default location ~/go , nothing unusual.

+6
source share
2 answers

cgo does not turn on by default when cross compiling. If you enable cgo, with CGO_ENABLED = 1 you will need to compile the c compiler for the target machine. This is not trivial.

I recommend if you need cgo to compile initially.

+9
source

If you need cgo cross corrections, I would point you to xgo , which I found very useful. It did not work in 100% of my use cases, but with some minor (compared to supporting native VMs for cross-compiling) changes in my code was enough.

0
source

All Articles