Skip to content
Advertisement

Cross-compilation of cgo (for darwin) fails

I am fairly new to go and even Linux in general.

I have built an app in a Linux environment which makes use of a gtk lib based on cgo (https://github.com/mattn/go-gtk/). The application builds fine in its native environment (linux 64bit) but when I try to compile for darwin 64bit I get the following result:

# net
could not determine kind of name for C.AI_MASK
# net
could not determine kind of name for C.AI_MASK

The command line I use to build:

env GOOS=$1 GOARCH=$2 CGO_ENABLED=1 go build $3

Where $1 is darwin and $2 amd64 (and $3 the path to my app).

As the error seems to come from the lib I import, I am not sure what to do to fix it. I have also read that cross compiling cgo does not really work as it relies on native macos stuff so it would need to be built on a mac. Is this true or is there something I can do to make it work in my environment?

I am also slightly confused as it seems most people discussing this subject are talking of go pre 1.5 which was entirely different when it comes to cross-compiling if I understand correctly.

Thanks

Advertisement

Answer

I am now able to compile successfully my code on linux for darwin thanks to the comments by JimB.

What I needed was a osx toolchain such as github.com/tpoechtrager/osxcross.

Then I compiled my code by doing env OSXCROSS_NO_INCLUDE_PATH_WARNINGS=1 MACOSX_DEPLOYMENT_TARGET=10.6 CC=o64-clang CXX=o64-clang++ GOOS=darwin GOARCH=amd64 CGO_ENABLED=1 go build -v mywork/myprogram.

Some of my programs compile successfully, some throw errors at linking time but I guess that’s another issue so I’ll mark this question as solved as far as the cross-compilation goes.

Advertisement