cross-compilation for go-gl applications

126 views
Skip to first unread message

Mads Horndrup

unread,
Jan 22, 2017, 10:57:39 PM1/22/17
to golang-nuts
Hi guys, I hope I'm posting this in the appropiate forum. It's difficult to find this kind of go-gl documentation.

I'm new to golang, but I'm experienced with OpenGL, usually through java wrappers. I'm using go-gl to access OpenGL through Go. I'm on a windows 10, 64-bit

For go-gl applications, how would cross-compilation work?

I read here that cross-compilation got better in go 1.5, and that now we can do this
env GOOS=darwin GOARCH=386 go build hello.go

^Sidequestion: What do I have to do to make this work in the windows cmd?

To get go-gl installed I just ran go get on these (while having a 64-bit windows gcc in path):
The gcc requirement makes me think the compiled go-gl application will somehow be tied to my system and arch. 

Is it possible to build for other platforms than the one I have compiled it on? How does the gcc affect how my application can be cross-platform?

Aram Hăvărneanu

unread,
Jan 23, 2017, 9:06:33 AM1/23/17
to Mads Horndrup, golang-nuts
Those packages use cgo, so you will need a gcc-based toolchain for
your target platform. Either you will have to build it yourself
(doing that on Windows is probably challenging), or perhaps you can
find a prebuilt gcc (good luck with that). Make sure to install the
relevant OpenGL headers and libraries for your target and that your
cross-compiler can find them.

Then you can just do something like (substitute for your target):

CGO_ENABLED=1 CC=sparcv9-solaris2.12-gcc GOOS=solaris GOARCH=sparc64 go build foo

Depending on a few other factors you might or might not need to
explicitely set internal or external linking.

CGO_ENABLED=1 CC=sparcv9-solaris2.12-gcc GOOS=solaris GOARCH=sparc64 go build -ldflags='-linkmode=external' foo

If I were you, I would rather find a way to build natively.

--
Aram Hăvărneanu
Reply all
Reply to author
Forward
0 new messages